我有以下类,我正在尝试测试方法AddRecordToQueue.
我正在使用Moq来模拟AddRecordToQueue方法中AddToQueue方法的结果.
AddToQueue方法返回一个布尔值,所以我试图用真值模拟结果
public class Test
{
private readonly IRabbitMqConnection rabbitMqConnection;
public Test(IRabbitMqConnection rabbitMqConnection)
{
this.rabbitMqConnection = rabbitMqConnection;
}
public bool AddRecordToQueue(string messageExchange, object data)
{
var jsonified = JsonConvert.SerializeObject(data);
var customerBuffer = Encoding.UTF8.GetBytes(jsonified);
var result = this.rabbitMqConnection.AddToQueue(customerBuffer, messageExchange);
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试类如下所示.
[TestClass]
public class TestCon
{
[TestMethod]
public void MockTest()
{
Moq.Mock<IRabbitMqConnection> rabbitConection = new Moq.Mock<IRabbitMqConnection>();
var draftContactsManager = new Test(rabbitConection.Object);
rabbitConection.Setup(e => e.AddToQueue(null, string.Empty)).Returns((bool res) => true);
var result = draftContactsManager.AddRecordToQueue("someExchange", null);
Assert.IsTrue(result);
}
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法将moq结果设置为true.任何人都可以建议我缺少什么 …
我尝试使用独立应用程序使用WCF Web服务.我能够使用Internet Explorer查看此服务,也可以在Visual Studio服务引用中查看.
这是我得到的错误
The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8).
Run Code Online (Sandbox Code Playgroud)
如何更改此选项以使用正确的内容类型?
这是我的配置文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="G2WebServiceSoap11Binding" />
</basicHttpBinding>
<customBinding>
<binding name="G2WebServiceSoap12Binding">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap11Endpoint/"
binding="basicHttpBinding" bindingConfiguration="G2WebServiceSoap11Binding"
contract="G2ServiceReference.G2WebServicePortType"
name="G2WebServiceHttpSoap11Endpoint" />
<endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap12Endpoint/"
binding="customBinding" bindingConfiguration="G2WebServiceSoap12Binding"
contract="G2ServiceReference.G2WebServicePortType"
name="G2WebServiceHttpSoap12Endpoint" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
这是堆栈
{System.ServiceModel.ProtocolException: The content type application/xml;charset=utf-8 of …Run Code Online (Sandbox Code Playgroud) 我正在尝试将字符串转换为日期时间
我一直在用
DateTime convertedDate = DateTime.Parse(lastModificationDate);
Run Code Online (Sandbox Code Playgroud)
转换日期
我的问题是,有时日期将采用英国格式,有时采用美国格式
即英国11/09/2011 10:34
美国2/28/2010 13:56
当我不确定字符串将采用哪种格式,即我们或英国时,如何处理这两种格式?
我正在尝试使用以下查询在表中创建逗号分隔的名称列表
DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',' ,'') + Name
FROM Production.Product
SELECT @listStr
Run Code Online (Sandbox Code Playgroud)
这工作正常,但列表确实包含重复项
任何人都可以建议我如何使这个DISTINCT列表不包含重复.
我正在尝试使用quartz.net创建一个作业,该作业将在开始时间和结束时间之间每45分钟运行一次
我试图使用cron tigger创建它
cronExpression ="0 0/45 8-5**?";
但是这不是我想要的方式.
在查看quartz.net教程之后,建议实现这样的工作需要使用两个触发器.
我对如何实现这一点感到有些困惑,任何人都可以就解决方案提出建议
我一直在玩RabbitMq.net和消息致谢.如果消费者能够处理消息,您可以以形式发回一个确认
channel.BasicAck(ea.DeliveryTag, false);
Run Code Online (Sandbox Code Playgroud)
这将把它从队列中删除.
但是,如果邮件无法处理呢?也许是暂时的中断,你不希望从队列中取出的消息只是放在后面并继续下一条消息?
我试过用
channel.BasicNack(ea.DeliveryTag, false, true);
Run Code Online (Sandbox Code Playgroud)
但下一次它仍然得到相同的消息而不是移动到队列中的下一条消息
我的完整代码是
class Program
{
private static IModel channel;
private static QueueingBasicConsumer consumer;
private static IConnection Connection;
static void Main(string[] args)
{
Connection = GetRabbitMqConnection();
channel = Connection.CreateModel();
channel.BasicQos(0, 1, false);
consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume("SMSQueue", false, consumer);
while (true)
{
if (!channel.IsOpen)
{
throw new Exception("Channel is closed");
}
var ea = consumer.Queue.Dequeue();
string jsonified = Encoding.UTF8.GetString(ea.Body);
var message = JsonConvert.DeserializeObject<SmsRecords>(jsonified);
if (ProcessMessage())
channel.BasicAck(ea.DeliveryTag, false);
else
channel.BasicNack(ea.DeliveryTag, false, true);
} …Run Code Online (Sandbox Code Playgroud) 我试图替换字符串中的值和另一个值的所有出现
到目前为止我所拥有的是什么
var result = "Cooker Works"
var searchterm = "cooker wor";
searchterm.split(" ").forEach(function (item) {
result = result.replace(new RegExp(item, 'g'), "<strong>" + item + "</strong>");
});
console.log(result)Run Code Online (Sandbox Code Playgroud)
我想要的结果应该是这样的
result = "<strong>Cooker</strong> <strong>Wor</strong>s";
Run Code Online (Sandbox Code Playgroud)
我在处理案件时遇到问题,有什么方法可以忽略这一点,但仍然得到我追求的结果
我试图在C#中设置一个2d数组作为迷宫来移动一个角色,我有几个问题初始化阵列,我试图做下面的
但是InitialiseMaze方法是说没有声明迷宫
任何人都可以建议
谢谢
西蒙
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GameMan
{
public class Maze
{
#region Variables
static int[,] maze;
#endregion
#region Constructors/Destructors
public Maze()
{
InitaliseMaze();
}
~Maze()
{
}
#endregion
#region Methods
public void InitaliseMaze()
{
maze = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, …Run Code Online (Sandbox Code Playgroud) 尝试使用 Azure DevOps Services Rest Api
https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-5.1
任何人都可以建议调用正确的 API 来获取存储库的已完成拉取请求列表
我一直在研究 Git Api,但似乎特定的 API 只返回尚未完成的 PR。
我有以下查询,我用来更新性别列,如果它设置为男性,然后更新为M,为女性,更新到F
该声明第一次正常运行.
UPDATE [People].[People]
SET GENDER = CASE WHEN GENDER = 'Male' THEN 'M'
WHEN GENDER = 'Female' THEN 'F' END WHERE Id=40
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果性别已经是'M',那么当再次运行该语句时,'M'被设置为NULL
我可以在下面做,但它似乎有点软糖
UPDATE [People].[People]
SET GENDER = CASE WHEN GENDER = 'Male' THEN 'M'
WHEN GENDER = 'Female' THEN 'F'
WHEN GENDER = 'M' THEN 'M'
WHEN GENDER = 'F' THEN 'F'
END WHERE Id=40
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议吗?
谢谢
我有一个saga,如果从调用返回的状态成功,saga结束,则每隔30秒检查一次API调用的状态,如果不是saga等待30秒并再次尝试.如果API调用未在60分钟内返回成功响应,则传奇超时并结束.
我在解除60分钟超时时遇到问题.我的代码是
public class MonitorSubmissionFeedSagaData: IContainSagaData
{
public Guid Id { get; set; }
public string Originator { get; set; }
public string OriginalMessageId { get; set; }
public bool TimeoutSet { get; set; }
[Unique]
public string JobId { get; set; }
}
public class MonitorSubmissionFeedSaga : Saga<MonitorSubmissionFeedSagaData>,
IAmStartedByMessages<MonitorFeedSubmissonCommand>,
IHandleMessages<StartCheckSubmissionCommand>,
IHandleTimeouts<MonitorSubmissionFeedSagaTimeout>
{
public const int SagaTimeoutInMinutes = 60;
public IEmpathyBrokerClientApi PostFileService { get; set; }
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<MonitorSubmissionFeedSagaData> mapper)
{
mapper.ConfigureMapping<MonitorFeedSubmissonCommand>(x => x.JobId).ToSaga(saga => saga.JobId);
}
public void …Run Code Online (Sandbox Code Playgroud) 我有一个在Visual Studio 2015中运行时构建良好的解决方案,但是当我从命令行运行时,我遇到了错误
错误CS1056:此行上出现意外字符'$'
var CutOffTextFragment = deadLineTime.Deadline.Minute == 0 ? $"{deadLineTime.Deadline:htt}" : $"{deadLineTime.Deadline:h:mmtt}"
Run Code Online (Sandbox Code Playgroud)
deadLineTime.Deadline是一个DateTime对象,代码将返回XAM/PM或X:XXAM/PM
我认为这是因为构建脚本没有使用C#6.目前这个脚本不能改为使用c#6
如果是这种情况,任何人都可以帮我折旧代码,以便它适用于C#5
当我从sqldatareader读取数据时,出现错误“关闭读取器时,无效尝试调用Read”。我的代码如下
显然,这已被ExecSqlDataReader中的using语句关闭
我希望能够调用此方法,然后在另一个类中使用阅读器,是否有办法绕过这个问题而不必在ExecSqlDataReader方法中遍历SqlDataReader?
希望有道理
谢谢
码:
SqlDataReader reader = data.ExecSqlDataReader(1);
while (reader.Read())
{
.....
}
public SqlDataReader ExecSqlDataReader(int queryType = 0)
{
using (var conn = new SqlConnection(this.ConnectionString))
{
try
{
PrepareCommandForExecution(conn, queryType);
return _cmd.ExecuteReader();
}
finally
{
_cmd.Connection.Close();
}
}
}
private SqlCommand PrepareCommandForExecution(SqlConnection conn, int sqlType = 0)
{
_cmd.Connection = conn;
switch (sqlType)
{
case 0:
_cmd.CommandType = CommandType.StoredProcedure;
break;
case 1:
_cmd.CommandType = CommandType.Text;
_cmd.CommandText = _tSqltext;
break;
case 2:
_cmd.CommandType = CommandType.TableDirect;
break;
}
_cmd.CommandTimeout …Run Code Online (Sandbox Code Playgroud) c# ×10
t-sql ×2
.net ×1
arrays ×1
azure-devops ×1
case ×1
javascript ×1
moq ×1
msbuild ×1
msmq ×1
nservicebus ×1
quartz.net ×1
rabbitmq ×1
regex ×1
sql ×1
unit-testing ×1
wcf ×1
wcf-binding ×1