public void Setup() { var resource = new AccountResource(); var persistentModel = new AccountEntity(); var context = new PutContext <AccountResource, AccountEntity>(resource, new ValidationState()) { PersistentModel = persistentModel }; var eTagProvider = Stub <IETagProvider>(); eTagProvider.Stub(x => x.GetETag(null)) .IgnoreArguments() .Throw(new Exception("Some Fun Exception")); StubRepository <AccountEntity> repository = New.StubRepository <AccountEntity>() .ResourceIsNeverCreatedOrModified; var step = new PersistEntityModel <PutContext <AccountResource, AccountEntity>, PutResult, AccountResource, AccountEntity>( repository, eTagProvider); step.ExecuteAsync(context, _putResult, CancellationToken.None).WaitSafely(); }
private StubRepository LoadRepository(string methodName, StubModeType?defaultMode) { var stubMethodPath = GetMethodStubPath(methodName); var repository = StubRepository.Load(stubMethodPath, defaultMode); return(repository); }
private static CallInfo CreateCallInfo(IMethodInvocation input, StubRepository rep) { var callInfo = rep.CreateCall( input.MethodBase, input.Target.GetType().AssemblyQualifiedName); return(callInfo); }
public void WhenEverythingIsOK_ThenInsertTheGroup() { var stubRepository = new StubRepository<Group>(); var groupCommand = CreateCreateGroupCommand(cudGroup: stubRepository); var @group = new Group { Name = "test"}; groupCommand.Execute(@group); stubRepository.Entities.Should().Contain(@group); }
public void WhenJustGroupIsMissing_ThenInsertTheTopic() { var name = "Test"; var stubRepository = new StubRepository<Topic>(); var command = CreateCreateTopicCommand(cudTopic: stubRepository); var topic = new Topic { Name = name }; command.Execute(topic); stubRepository.Entities.Should().Contain(topic); }
public void WhenAllIsOk_ThenUpdate() { var repository = new StubRepository<Subscription>(); var command = CreateCommand(repository: repository); var subscription = new Subscription { Id = Identity.Random() }; command.Execute(subscription); repository.Updates.Should().Contain(subscription); }
private static CallInfo MakeCallStub(IMethodInvocation input, StubRepository rep, IMethodReturn result) { var callInfo = CreateCallInfo(input, rep); var inargs = CreateInParameters(input, callInfo); var outargs = CreateOutParameters(input, callInfo, result); var resarg = CreateReturnParameter(input, callInfo, result); callInfo.SetParameters(inargs, outargs, resarg); return(callInfo); }
public void WhenAllIsOk_ThenInsert() { var stubRepository = new StubRepository<Subscription>(); var command = CreateCommand(repository: stubRepository); var targetId = Identity.Random(); var subscription = new Subscription { TargetId = targetId }; command.Execute(subscription); stubRepository.Entities.Should().Contain(subscription); }
public void WhenAllIsOk_ThenDelete() { var identity = Identity.Random(); var entityById = Mock.Of<IEntityById>(eb => eb.Exist<Subscription>(It.IsAny<Identity>()) == true); var repository = new StubRepository<Subscription>(new Subscription{Id = identity}); var command = new DeleteSubscriptionCommand(entityById, repository); command.Execute(identity); repository.Entities.Should().Be.Empty(); }
public void WhenEverythingIsOK_ThenUpdateTheGroup() { var id = Identity.Random(); var stubRepository = new StubRepository<Group>(); var groupCommand = CreateUpdateGroupCommand(entityById: Mock.Of<IEntityById>(q => q.Exist<Group>(id)), cudGroup: stubRepository); var @group = new Group { Id=id, Name = "test" }; groupCommand.Execute(@group); stubRepository.Updates.Should().Contain(@group); }
public void WhenGroupExists_ThenDelete() { var groupId = Identity.Random(12); var repository = new StubRepository<Group>(new Group { Id = groupId}); var command = CreateCommand(Mock.Of<IEntityById>(q => q.Exist<Group>(It.IsAny<Identity>()) == true), repository); command.Execute(groupId); repository.Entities.Should().Be.Empty(); }
public void WhenTopicExists_ThenDelete() { var id = Identity.Random(); var repository = new StubRepository<Topic>(new Topic { Id = id }); var command = CreateCommand(Mock.Of<IEntityById>(q => q.Exist<Topic>(id)==true), repository); command.Execute(id); repository.Entities.Should().Be.Empty(); }
public void WhenEverythingIsOK_ThenInsertTheTopic() { var name = "Test"; var groupId = Identity.Random(); var stubRepository = new StubRepository<Topic>(); var command = CreateCreateTopicCommand(entityById: Mock.Of<IEntityById>(q => q.Exist<Group>(groupId)), cudTopic: stubRepository); var topic = new Topic { Name = name, GroupId = groupId }; command.Execute(topic); stubRepository.Entities.Should().Contain(topic); }
public void WhenAllIsOk_ThenUpdate() { var repository = new StubRepository <Subscription>(); var command = CreateCommand(repository: repository); var subscription = new Subscription { Id = Identity.Random() }; command.Execute(subscription); repository.Updates.Should().Contain(subscription); }
public void WhenEverythingIsOK_ThenInsertTheGroup() { var stubRepository = new StubRepository <Group>(); var groupCommand = CreateCreateGroupCommand(cudGroup: stubRepository); var @group = new Group { Name = "test" }; groupCommand.Execute(@group); stubRepository.Entities.Should().Contain(@group); }
public void WhenGroupExists_ThenDelete() { var groupId = Identity.Random(12); var repository = new StubRepository <Group>(new Group { Id = groupId }); var command = CreateCommand(Mock.Of <IEntityById>(q => q.Exist <Group>(It.IsAny <Identity>()) == true), repository); command.Execute(groupId); repository.Entities.Should().Be.Empty(); }
public void WhenAllIsOk_ThenInsert() { var stubRepository = new StubRepository <Subscription>(); var command = CreateCommand(repository: stubRepository); var targetId = Identity.Random(); var subscription = new Subscription { TargetId = targetId }; command.Execute(subscription); stubRepository.Entities.Should().Contain(subscription); }
public void WhenJustGroupIsMissing_ThenInsertTheTopic() { var name = "Test"; var stubRepository = new StubRepository <Topic>(); var command = CreateCreateTopicCommand(cudTopic: stubRepository); var topic = new Topic { Name = name }; command.Execute(topic); stubRepository.Entities.Should().Contain(topic); }
public void WhenTopicExists_ThenDelete() { var id = Identity.Random(); var repository = new StubRepository <Topic>(new Topic { Id = id }); var command = CreateCommand(Mock.Of <IEntityById>(q => q.Exist <Topic>(id) == true), repository); command.Execute(id); repository.Entities.Should().Be.Empty(); }
public void WhenJustGroupIsMissing_ThenUpdateTheTopic() { var stubRepository = new StubRepository<Topic>(); var id = Identity.Random(); var name = "Test"; var command = CreateUpdateTopicCommand( entityById: Mock.Of<IEntityById>(q => q.Exist<Topic>(id)), existsTopicByName: Mock.Of<IExistsTopicByName>(q => q.Execute(null, name, id) == false), cudTopic: stubRepository); var topic = new Topic { Id = id, Name = name }; command.Execute(topic); stubRepository.Updates.Should().Contain(topic); }
public void WhenEverythingIsOK_ThenUpdateTheGroup() { var id = Identity.Random(); var stubRepository = new StubRepository <Group>(); var groupCommand = CreateUpdateGroupCommand(entityById: Mock.Of <IEntityById>(q => q.Exist <Group>(id)), cudGroup: stubRepository); var @group = new Group { Id = id, Name = "test" }; groupCommand.Execute(@group); stubRepository.Updates.Should().Contain(@group); }
public void WhenAllIsOk_ThenDelete() { var identity = Identity.Random(); var entityById = Mock.Of <IEntityById>(eb => eb.Exist <Subscription>(It.IsAny <Identity>()) == true); var repository = new StubRepository <Subscription>(new Subscription { Id = identity }); var command = new DeleteSubscriptionCommand(entityById, repository); command.Execute(identity); repository.Entities.Should().Be.Empty(); }
public void WhenEverythingIsOK_ThenInsertTheTopic() { var name = "Test"; var groupId = Identity.Random(); var stubRepository = new StubRepository <Topic>(); var command = CreateCreateTopicCommand(entityById: Mock.Of <IEntityById>(q => q.Exist <Group>(groupId)), cudTopic: stubRepository); var topic = new Topic { Name = name, GroupId = groupId }; command.Execute(topic); stubRepository.Entities.Should().Contain(topic); }
public void WhenEverythingIsOK_ThenUpdateTheTopic() { var stubRepository = new StubRepository <Topic>(); var id = Identity.Random(); var name = "Test"; var groupId = Identity.Random(); var command = CreateUpdateTopicCommand(entityById: Mock.Of <IEntityById>(q => q.Exist <Topic>(id) && q.Exist <Group>(groupId)), existsTopicByName: Mock.Of <IExistsTopicByName>(q => q.Execute(groupId, name, id) == false), cudTopic: stubRepository); var topic = new Topic { Id = id, Name = name, GroupId = groupId }; command.Execute(topic); stubRepository.Updates.Should().Contain(topic); }
public void WhenThereIsNotAchievedFeed_ThenCreateANewOneWithMessage() { var topicId = Identity.Random(); var feed = new Feed { TopicId = topicId }; var query = Mock.Of<IGetWorkingFeedForTopic>(q => q.Execute(topicId) == feed); var repository = new StubRepository<Feed>(); var handler = CreateHandler(repository, query); var message = new Message { Id = Identity.Random(), TopicId = topicId}; handler.Handle(new NewMessageEvent { Message = message }); repository.Updates .Satisfy(es => es.Count == 1 && es.First() == feed && es.First().Entries.Any(e => e.MessageId == message.Id)); }
public void Test_Create_SucceedsWithNoTimeTaken() { // Arrange IUnitOfWork stubUnitOfWork = MockRepository.GenerateStub<IUnitOfWork>(); StubRepository<Ride> stubRideRepository = new StubRepository<Ride>(); stubUnitOfWork.Stub(s => s.GetRepository<Ride>()).Return(stubRideRepository); RideService service = new RideService(stubUnitOfWork); DateTime dateRidden = new DateTime(2011, 01, 01); // Act bool result = service.Create(1, 1, dateRidden, null, null, null); // Assert Ride ride = stubRideRepository.InsertItems[0]; Assert.IsTrue(result); Assert.AreEqual(1, ride.RouteID); Assert.AreEqual(dateRidden, ride.TimeOfRide); Assert.AreEqual(null, ride.TimeTaken); Assert.AreEqual(1, ride.AccountID); stubUnitOfWork.AssertWasCalled(uw => uw.Save()); }
public void Setup() { var resource = new AccountResource(); var persistentModel = new AccountEntity(); var context = new PutContext <AccountResource, AccountEntity>(resource, new ValidationState()) { PersistentModel = persistentModel }; var eTagProvider = Stub <IETagProvider>(); StubRepository <AccountEntity> repository = New.StubRepository <AccountEntity>() .OnUpsertThrow(new Exception()); var step = new PersistEntityModel <PutContext <AccountResource, AccountEntity>, PutResult, AccountResource, AccountEntity>( repository, eTagProvider); step.ExecuteAsync(context, _putResult, CancellationToken.None).WaitSafely(); }
public void EditAction() { using (ShimsContext.Create()) { stubArticleInfoService = new StubArticleInfoService(); shimArticleInfoService = new ShimArticleInfoService(stubArticleInfoService); repository = new StubRepository <ArticleInfo, int>(new MockContent()); shimRepository = new ShimRepository <ArticleInfo, int>(repository); InitService(); shimArticleInfoService.Bind(repository); controller = new ArticleInfoController(shimArticleInfoService.Instance, 6) { ControllerContext = controllerContext }; controller.Edit("1"); } //Assert.IsTrue(1 == 1); }
public void WhenThereIsNotAchievedFeed_ThenCreateANewOneWithMessage() { var topicId = Identity.Random(); var feed = new Feed { TopicId = topicId }; var query = Mock.Of <IGetWorkingFeedForTopic>(q => q.Execute(topicId) == feed); var repository = new StubRepository <Feed>(); var handler = CreateHandler(repository, query); var message = new Message { Id = Identity.Random(), TopicId = topicId }; handler.Handle(new NewMessageEvent { Message = message }); repository.Updates .Satisfy(es => es.Count == 1 && es.First() == feed && es.First().Entries.Any(e => e.MessageId == message.Id)); }
public EquipmentServiceTest() { _stubRepository = new StubRepository(); _createEquipmentInRoom = new CreateEquipmentInRoom(); _createTransferEqupmentDTO = new CreateTransferEqupmentDTO(); }
public ScheduleRenovationTests() { _stubRepository = new StubRepository(); _createRenovaton = new CreateRenovation(); }
public EquipmentControllerTest() { _stubRepository = new StubRepository(); _createEquipmentInRoom = new CreateEquipmentInRoom(); }
public AppointmentSearchTest() { _stubRepository = new StubRepository(); }
public ScheduleAnAppointmentTest() { _stubRepository = new StubRepository(); _createExamination = new CreateExamination(); }
public void Test_Create_ThrowsServiceExceptionOnUnitOfWorkError() { // Arrange IUnitOfWork stubUnitOfWork = MockRepository.GenerateStub<IUnitOfWork>(); StubRepository<Ride> stubRideRepository = new StubRepository<Ride>(); stubUnitOfWork.Stub(s => s.GetRepository<Ride>()).Return(stubRideRepository); stubUnitOfWork.Stub(s => s.Save()).Throw(new Exception()); RideService service = new RideService(stubUnitOfWork); DateTime dateRidden = new DateTime(2011, 01, 01); bool exceptionThrown = false; // Act try { service.Create(1, 1, dateRidden, null, null, null); } catch (ServiceException) { exceptionThrown = true; } // Assert Assert.IsTrue(exceptionThrown); }