protected override void Given() { _hotelService = new HotelService(ObjectContextFake, RepositoryFake, null); A.CallTo(() => RepositoryFake.Add(null)).WithAnyArguments(). Invokes(call => ((Hotel)call.Arguments[0]).Id = HotelId); }
protected override void Given() { _hotelService = new HotelService(ObjectContextFake, RepositoryFake, null); A.CallTo(() => RepositoryFake.Get(null)).WithAnyArguments().Returns( new Hotel() { Id = 42, Name = "Test Beach Resort", Description = "Nice hotel on the beach", Image = "http://test.com/test.jpg", Facts = new Collection <Fact>() }); }
protected override void Given() { _hotelService = new HotelService(ObjectContextFake, RepositoryFake, null); _hotel = new Hotel() { Id = HotelId, Name = null, Description = null, Facts = new Collection <Fact>() }; A.CallTo(() => RepositoryFake.Get(null)).WithAnyArguments().Returns(_hotel); }
protected override void Given() { _hotelService = new HotelService(ObjectContextFake, RepositoryFake, null); _hotel = new Hotel() { Id = HotelId, Name = "Test Beach Hotel", Description = "A nice hotel situated right at Test Beach", Image = "http://test.com/test.jpg" }; A.CallTo(() => RepositoryFake.Get(null)).WithAnyArguments().Returns(_hotel); }
public void AddUser_DoesNotAddUser_WhenUserExists() { var repository = new RepositoryFake(); FindUserQuery fnq = FakeFindUserFake.UserFound(new User { UserName = "******", Id = 1 }); var interactor = GetAddUserInteractor(repository, fnq); var result = interactor.Execute("UserName"); Assert.That(result.OperationSuccess, Is.False); Assert.That(string.IsNullOrEmpty(result.SessionKey), Is.True); Assert.That(repository.InsertedItem.Count, Is.EqualTo(0)); }
internal void Receive( AggregateCommandHandler <Customer> handler, RepositoryFake <Customer> repo, IContext context, Customer customer, ID customerID ) { GIVEN["a handler instance and a service provider"] = () => { handler = new AggregateCommandHandler <Customer>(); IServiceProvider sp = new ServiceProviderFake().Register <IRepository <Customer> >( repo = Substitute.ForPartsOf <RepositoryFake <Customer> >()); context = new GenericContext(); context.Set(sp, false); }; When["sending a create message to the aggregate"] = () => Send(customerID = ID.NewID(), new Customer.Create()); Then["the aggregate gets created"] = async() => customer = await repo.Get(customerID); AND["it receives the command"] = () => customer.Commands.Should().BeEmpty(); When["sending a non-create message to the aggregate"] = () => { repo.ClearReceivedCalls(); customer.Commands.Clear(); return(Send(customerID, new Customer.Promote())); }; Then["the aggregate is loaded and saved"] = async() => { await repo.Received().Get(customerID); await repo.Received().Save(customer); }; AND["it receives the command"] = () => customer.Commands.Should().ContainSingle(m => m is Customer.Promote); When["sending a message that does not belong to the aggregate"] = () => { repo.ClearReceivedCalls(); return(Send(customerID, new Order.Ship())); }; THEN["no action is performed"] = () => repo.ReceivedCalls().Should().BeEmpty(); Task Send(ID target, ICommandMessage message) { Maybe <Task> result = handler.Receive(new HandleCommand( new Command(message, target), context)); return(result is Some <Task> t ? (Task)t : Task.CompletedTask); } }
public void AddUser_AddsUser_WhenNewUser() { var repository = new RepositoryFake(); FindUserQuery fnq = FakeFindUserFake.NoUserFound(); var interactor = GetAddUserInteractor(repository, fnq); var result = interactor.Execute("UserName"); Assert.That(result.OperationSuccess, Is.True); Assert.That(result.OperationSuccess, Is.True); Assert.That(result.SessionKey, Is.EqualTo(((UserSession)repository.InsertedItem[1]).SessionKey)); Assert.IsInstanceOf <User>(repository.InsertedItem[0]); Assert.That(((User)repository.InsertedItem[0]).UserName, Is.EqualTo("UserName")); Assert.That(((User)repository.InsertedItem[0]).Id, Is.EqualTo(1)); Assert.IsInstanceOf <UserSession>(repository.InsertedItem[1]); Assert.True(Regex.Match(((UserSession)repository.InsertedItem[1]).SessionKey, "^[{(]?[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$", RegexOptions.IgnoreCase).Success); Assert.That(((UserSession)repository.InsertedItem[1]).Id, Is.EqualTo(1)); }
public void SaveCredit_NotBankKredit() { // ПРОВЕРЯЕТ ВЫБРОС ОШИБКИ ПРИ НЕВЕРНОМ АРГУМЕНТЕ // инициализация var input = new NotCredit(); // выполнение SaveCredit SC = new SaveCredit(); RepositoryFake RF = new RepositoryFake(); try { bool rez = SC.Save(input, RF); Assert.Fail(); } catch { } finally { } // сравнение }
public void SaveCredit_BankCredit() { // ПРОВЕРЯЕТ НА ВХОЖДЕНИЕ ПОСЛЕ ДОБАВЛЕНИЯ // инициализация var input = ClientsFactory.GetCredit("кр", 1, 1, 1, 0, "цель"); // выполнение SaveCredit SC = new SaveCredit(); RepositoryFake RF = new RepositoryFake(); bool rez = SC.Save(input, RF); // сравнение if (RF.CurrentList.FirstOrDefault() != input) { Assert.Fail(); } //Assert.AreEqual(true, rez); }
private static AddUserInteractor GetAddUserInteractor(RepositoryFake repository, FindUserQuery findUserQuery) { var interactor = new AddUserInteractor(repository, findUserQuery); return(interactor); }
public void Then_Hotel_Is_Deleted() { A.CallTo(() => RepositoryFake.Delete(null)).WhenArgumentsMatch(ac => ac.Get <Hotel>(0).Id == HotelId).MustHaveHappened(Repeated.Exactly.Once); }
protected override void Given() { _hotelService = new HotelService(ObjectContextFake, RepositoryFake, null); A.CallTo(() => RepositoryFake.Get(null)).WithAnyArguments().Returns(null); }
public void Then_Image_Of_Added_Hotel_Is_Correct() { A.CallTo(() => RepositoryFake.Add(null)).WhenArgumentsMatch(a => a.Get <Hotel>(0).Image == "http://test.com/test.jpg").MustHaveHappened(Repeated.Exactly.Once); }
public void Then_Description_Of_Added_Hotel_Is_Correct() { A.CallTo(() => RepositoryFake.Add(null)).WhenArgumentsMatch(a => a.Get <Hotel>(0).Description == "A nice hotel situated right at Test Beach").MustHaveHappened(Repeated.Exactly.Once); }
public void Then_Name_Of_Added_Hotel_Is_Correct() { A.CallTo(() => RepositoryFake.Add(null)).WhenArgumentsMatch(a => a.Get <Hotel>(0).Name == "Test Beach Hotel").MustHaveHappened(Repeated.Exactly.Once); }
public void Then_Hotel_Is_Added() { A.CallTo(() => RepositoryFake.Add(null)).WithAnyArguments().MustHaveHappened(Repeated.Exactly.Once); }