本文整理汇总了C#中Mock.SetReturnsDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.SetReturnsDefault方法的具体用法?C# Mock.SetReturnsDefault怎么用?C# Mock.SetReturnsDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.SetReturnsDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Given
public void Given()
{
gateway = new Mock<Gateway>();
gateway.SetReturnsDefault(true);
obj = new Mock<StatefulObject>();
obj.SetReturnsDefault(obj.Object);
}
示例2: when_finding_non_existing_assignment_then_returns_null
public void when_finding_non_existing_assignment_then_returns_null()
{
var storage = new Mock<IBlobStorage>();
storage.SetReturnsDefault<byte[]>(null);
var dao = new OrderDao(() => new ConferenceRegistrationDbContext("OrderDaoFixture"), storage.Object, Mock.Of<ITextSerializer>());
var dto = dao.FindOrderSeats(Guid.NewGuid());
Assert.Null(dto);
}
示例3: UseAutofacLifetimeScopeInjectorDoesntAddWrappedMiddlewareInstancesToAppBuilder
public void UseAutofacLifetimeScopeInjectorDoesntAddWrappedMiddlewareInstancesToAppBuilder()
{
var builder = new ContainerBuilder();
builder.RegisterType<TestMiddleware>();
var container = builder.Build();
var app = new Mock<IAppBuilder>();
app.Setup(mock => mock.Properties).Returns(new Dictionary<string, object>());
app.SetReturnsDefault(app.Object);
app.Object.UseAutofacLifetimeScopeInjector(container);
app.Verify(mock => mock.Use(It.IsAny<AutofacMiddleware<TestMiddleware>>(), It.IsAny<object[]>()), Times.Never);
}
示例4: CreateShareLink_CreatedLinkAndToken
public void CreateShareLink_CreatedLinkAndToken()
{
// arrange
var pathHelper = new Mock<IPathHelper>();
var hashService = new HashService();
var shareService = new ShareService(pathHelper.Object, hashService);
pathHelper.SetReturnsDefault("/user/share");
// act
var link = shareService.CreateShareLink("[email protected]");
// assert
link.Should().Contain("/user/share/[email protected]?key=");
}
示例5: RecordCalculation_ProvideCalcuation_Should_populate_stream_with_csv
public void RecordCalculation_ProvideCalcuation_Should_populate_stream_with_csv()
{
var calculation = new Calculation { Answer = 2.1, Operation = "theOperation", Probability1 = 0.3, Probability2 = 0.6 };
var memoryStream = new MemoryStream();
var mockClock = new Mock<IClock>();
mockClock.SetReturnsDefault(new DateTime(2000, 1, 10, 10, 12, 30));
var logger = new Logger(memoryStream, mockClock.Object);
logger.RecordCalculation(calculation);
byte[] buffer = memoryStream.ToArray();
var result = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
Assert.AreEqual("10/01/2000 10:12:30,0.3,0.6,2.1,theOperation\r\n", result);
}
示例6: CanPerformActivityAsync_PassDelegateParameter_ReturnTrue
public async Task CanPerformActivityAsync_PassDelegateParameter_ReturnTrue()
{
// Arrange
var mockPredicate = new Mock<Func<UserAuthorisation, string, Task<bool>>>();
mockPredicate.SetReturnsDefault(Task.FromResult(true));
var user = new UserAuthorisation(userName);
// Act
var result = await user.CanPerformActivityAsync("READ", mockPredicate.Object);
// Assert
Assert.IsTrue(result);
mockPredicate.Verify(p => p(user, "READ"), Times.Once);
}
示例7: ValidateShareKey_WrongKey
public void ValidateShareKey_WrongKey()
{
var pathHelper = new Mock<IPathHelper>();
var hashService = new HashService();
var shareService = new ShareService(pathHelper.Object, hashService);
pathHelper.SetReturnsDefault("/user/share");
var key = "dd12113dcb92ffeb0d7afaf0261fAAAA";
// act
var result = shareService.ValidateShareKey("[email protected]", key);
// assert
result.Should().Be.False();
}
示例8: CanPerformActivity_MockDelegate_ReturnTrue
public void CanPerformActivity_MockDelegate_ReturnTrue()
{
// Arrange
var mockCanPerformActivityHandler = new Mock<Func<UserAuthorisation,string, bool>>();
mockCanPerformActivityHandler.SetReturnsDefault(true);
var user = new UserAuthorisation(userName)
.AddCanPerformActivityDelegate(mockCanPerformActivityHandler.Object);
// Act
var result = user.CanPerformActivity("READ");
// Assert
Assert.IsTrue(result);
mockCanPerformActivityHandler.Verify(u => u(user, "READ"), Times.Once);
}
示例9: SendAfterOpenDoesBehavesCorrectlyForConfiguredQueuingBehavior
public void SendAfterOpenDoesBehavesCorrectlyForConfiguredQueuingBehavior(QueuingBehavior queuingBehavior, int expectedCounter)
{
var perfCounters = new Mock<IPerformanceCounterManager>();
var queueLengthCounter = new Mock<IPerformanceCounter>();
var counterIncrementCount = 0;
queueLengthCounter.Setup(c => c.Increment()).Callback(() => counterIncrementCount++);
perfCounters.DefaultValue = DefaultValue.Mock;
perfCounters.SetReturnsDefault(new NoOpPerformanceCounter());
perfCounters.SetupAllProperties();
perfCounters.Setup(pc => pc.ScaleoutSendQueueLength).Returns(queueLengthCounter.Object);
var stream = new ScaleoutStream(new TraceSource("Queue"), "0", queuingBehavior, 1000, perfCounters.Object);
stream.Send(_ => TaskAsyncHelper.Empty, null);
stream.Open();
stream.Send(_ => TaskAsyncHelper.Empty, null).Wait();
Assert.Equal(expectedCounter, counterIncrementCount);
}
示例10: Should_Delete_Media_With_Access_Rules
public void Should_Delete_Media_With_Access_Rules()
{
RunActionInTransaction(session =>
{
var uow = new DefaultUnitOfWork(session);
var repository = new DefaultRepository(uow);
var accessControlService = new Mock<IAccessControlService>().Object;
var commandContext = new Mock<ICommandContext>().Object;
var cmsConfiguration = Container.Resolve<ICmsConfiguration>();
var httpContextAccessor = new Mock<IHttpContextAccessor>();
httpContextAccessor.SetReturnsDefault("http://wwww.bcms.com/uploads/trash");
var file = TestDataProvider.CreateNewMediaFileWithAccessRules(3);
session.SaveOrUpdate(file);
session.Flush();
session.Clear();
var mediaService = new DefaultMediaService(repository, uow, accessControlService, cmsConfiguration);
var command = new DeleteMediaCommand(mediaService);
command.Repository = repository;
command.UnitOfWork = uow;
command.Context = commandContext;
var result = command.Execute(new DeleteMediaCommandRequest
{
Id = file.Id,
Version = file.Version
});
Assert.IsTrue(result);
session.Clear();
var deletedFile = session.Query<MediaFile>().FirstOrDefault(f => f.Id == file.Id && !f.IsDeleted);
Assert.IsNull(deletedFile);
});
}
示例11: ReturnsDefaultValueOnProperty
public void ReturnsDefaultValueOnProperty()
{
var mock = new Mock<IFoo>();
mock.SetReturnsDefault(int.MinValue);
Assert.Equal(int.MinValue, mock.Object.Value);
}
示例12: ReturnsDefaultValueType
public void ReturnsDefaultValueType()
{
var mock = new Mock<IFoo>();
mock.SetReturnsDefault(true);
Assert.Equal(true, mock.Object.ReturnBool());
}
示例13: ReturnsDefaultReferenceValue
public void ReturnsDefaultReferenceValue()
{
var mock = new Mock<IFoo>();
mock.SetReturnsDefault<IList<int>>(new List<int>());
Assert.NotNull(mock.Object.ReturnIntList());
}
示例14: UseMiddlewareFromContainerRequiresInjectorRegistrationFirst
public void UseMiddlewareFromContainerRequiresInjectorRegistrationFirst()
{
var app = new Mock<IAppBuilder>();
app.Setup(mock => mock.Properties).Returns(new Dictionary<string, object>());
app.SetReturnsDefault(app.Object);
Assert.Throws<InvalidOperationException>(() => app.Object.UseMiddlewareFromContainer<TestMiddleware>());
}
示例15: IsInRoleAsync_AddDelegateDuringInitialisation_ReturnTrue
public async Task IsInRoleAsync_AddDelegateDuringInitialisation_ReturnTrue()
{
// Arrange
var mockPredicate = new Mock<Func<UserAuthorisation, string, Task<bool>>>();
mockPredicate.SetReturnsDefault(Task.FromResult(true));
var user = new UserAuthorisation(userName)
.AddAsyncIsInRoleDelegate(mockPredicate.Object);
// Act
var result = await user.IsInRoleAsync("DATAREADER");
// Assert
Assert.IsTrue(result);
mockPredicate.Verify(p => p(user, "DATAREADER"), Times.Once);
}