[Fact] // async Task<IEnumerable<OwnerAllTransactionRequestsServiceModel>> GetAllTransactionRequestsAsync(string userId) public async void GetAllTransactionRequestsAsync_ForGivenOwnerId_ShouldReturnModelCollection() { // Arrange var id = 1; var country = CountryCreator.Create(); var city = CityCreator.Create(country.Id); var tenant = UserCreator.Create("Shunko", "Svinski", "shunkata", "*****@*****.**"); var owner = UserCreator.Create("Suzdurma", "Saturov", "satura", "*****@*****.**"); var home = HomeCreator.CreateOwnerHome(owner.Id, city.Id); var home2 = HomeCreator.CreateManagedHome(owner.Id, city.Id); var contract = ContractCreator.CreateRentalContract(id); var rental = RentalCreator.Create(id, country, city, tenant, home, contract); var anotherId = 2; var anotherTenant = UserCreator.Create("Fileslav", "Karadjolanov", "fileto", "*****@*****.**"); var anotherOwner = UserCreator.Create("Prasemir", "Babek", "nadenicata", "*****@*****.**"); var anotherHome = HomeCreator.CreateOwnerHome(anotherOwner.Id, city.Id); var anotherContract = ContractCreator.CreateRentalContract(anotherId); var anotherRental = RentalCreator.Create(anotherId, country, city, anotherTenant, anotherHome, anotherContract); var trId = Guid.NewGuid().ToString(); var trId2 = Guid.NewGuid().ToString(); var trId5 = Guid.NewGuid().ToString(); var transactionRequest = TransactionRequestCreator.CreateForRental(trId, tenant.Id, owner.Id, rental.Id); var transactionRequest2 = TransactionRequestCreator.CreateForManager(trId2, owner.Id, home2.ManagerId, home2.Id); var transactionRequest5 = TransactionRequestCreator.CreateForRental(trId5, anotherTenant.Id, anotherOwner.Id, anotherRental.Id); await this.Context.Countries.AddAsync(country); await this.Context.Cities.AddAsync(city); await this.Context.Users.AddRangeAsync(owner, tenant, anotherTenant); await this.Context.Homes.AddRangeAsync(home, home2); await this.Context.Contracts.AddRangeAsync(contract, anotherContract); await this.Context.Rentals.AddRangeAsync(rental, anotherRental); await this.Context .TransactionRequests .AddRangeAsync(transactionRequest, transactionRequest2, transactionRequest5); await this.Context.SaveChangesAsync(); var service = new OwnerTransactionRequestService(this.Context); // Act var result = await service.GetAllTransactionRequestsAsync(owner.Id); // Assert result.Should().AllBeOfType <OwnerAllTransactionRequestsServiceModel>(); result.Should().HaveCount(2, "because there are 2 different contracts - one home rented and another managed"); }
[Fact] // 5. async Task<bool> AddPaymentRequestToUserAsync(string userId, string requestId) public async void AddPaymentRequestToUserAsync_WithGivenUserIdAndRequestId_ShouldAddPaymentToUserSuccessfully() { // Arrange var ownerId = Guid.NewGuid().ToString(); var anotherOwnerId = Guid.NewGuid().ToString(); var country = CountryCreator.Create(); var city = CityCreator.Create(country.Id); var home1 = HomeCreator.CreateAny(city.Id); // rented var home2 = HomeCreator.CreateManagedHome(ownerId, city.Id); // managed var tenant1 = UserCreator.Create("Debelin", "Butov", "but4eto", "*****@*****.**"); int id1 = 1; var contract1 = ContractCreator.CreateRentalContract(id1); var rental1 = RentalCreator.Create(id1, country, city, tenant1, home1, contract1); var payment1 = PaymentCreator.CreateForTenant(home1.Owner, tenant1.Id, rental1.Id); var payment2 = PaymentCreator.CreateForManager(home1.Owner.Id, home2.Manager.Id, home2.Id); var senderId = Guid.NewGuid().ToString(); var recipientId = Guid.NewGuid().ToString(); var trId = Guid.NewGuid().ToString(); var transactionRequest = TransactionRequestCreator .CreateForManager(trId, home1.Owner.Id, home2.Manager.Id, home2.Id); await this.Context.Countries.AddAsync(country); await this.Context.Cities.AddAsync(city); await this.Context.Homes.AddAsync(home1); await this.Context.Users.AddAsync(tenant1); await this.Context.Rentals.AddRangeAsync(rental1); await this.Context.Payments.AddRangeAsync(payment1, payment2); await this.Context.Contracts.AddRangeAsync(contract1); await this.Context.TransactionRequests.AddRangeAsync(transactionRequest); await this.Context.SaveChangesAsync(); var transactionRequestService = new Mock <IOwnerTransactionRequestService>(); transactionRequestService.Setup(x => x.FindByIdAsync(trId)) .Returns(Task.FromResult(transactionRequest)); var service = new PaymentCommonService( this.Context, transactionRequestService.Object, this.UserManager.Object, null); // Act var result = await service.AddPaymentRequestToUserAsync(home1.Owner.Id, trId); var createdPaymentTo = await this.Context.Payments .Where(p => p.HomeId == home2.Id) .FirstOrDefaultAsync(); // Assert result.Should().BeTrue(); createdPaymentTo.Should().NotBeNull(); }