private List <BusyDate> MakeListBusyDates(IEnumerable <DateTime> dates, Guid apartmentId) { List <BusyDate> busyDates = new List <BusyDate>(); foreach (var item in dates) { BusyDate date = new BusyDate() { ApartmentId = apartmentId, Date = item.Date }; busyDates.Add(date); } return(busyDates); }
public async void UpdateOrderAsync_Positive_TestAsync() { var options = new DbContextOptionsBuilder <ApartmentContext>() .UseInMemoryDatabase(databaseName: "UpdateOrderAsync_PositiveAndNegative_TestAsync") .Options; using (var context = new ApartmentContext(options)) { Country country = new Country() { Name = "Litva" }; context.Add(country); context.AddRange(_users); await context.SaveChangesAsync(); User userWithOrders = context.Users.AsNoTracking().FirstOrDefault(); foreach (var item in _addresses) { item.CountryId = context.Countries.FirstOrDefault().Id; } for (int i = 0; i < 2; i++) { _apartments[i].OwnerId = userWithOrders.Id; _apartments[i].Address = _addresses[i]; } context.AddRange(_apartments); await context.SaveChangesAsync(); Apartment apartmentWithOrders = context.Apartments.AsNoTracking().FirstOrDefault(); Order order = new Order() { ApartmentId = apartmentWithOrders.Id, CustomerId = userWithOrders.Id, }; List <BusyDate> busyDates = new List <BusyDate>(); BusyDate date = new BusyDate() { ApartmentId = apartmentWithOrders.Id, Date = DateTime.Now.Date }; busyDates.Add(date); order.Dates = _mapper.Map <HashSet <BusyDate> >(busyDates); context.AddRange(order); await context.SaveChangesAsync(); } using (var context = new ApartmentContext(options)) { var service = new OrderUserService(context, _mapper); var orderInBase = await context.Orders.AsNoTracking().FirstOrDefaultAsync(); var orderForUpdate = _mapper.Map <OrderDTO>(orderInBase); DateTime newDate = new DateTime(DateTime.Now.Year + 1, DateTime.Now.Month, DateTime.Now.Day); IEnumerable <DateTime> dates = new List <DateTime>() { newDate }; orderForUpdate.Dates = dates; var resultPositive = await service.UpdateOrderAsync(orderForUpdate); resultPositive.IsSuccess.Should().BeTrue(); //resultPositive.Data.Order.Dates.FirstOrDefault().Should().BeSameDateAs(newDate); } }
public async void DeleteOrderByIdAsync_PositiveAndNegative_TestAsync() { var options = new DbContextOptionsBuilder <ApartmentContext>() .UseInMemoryDatabase(databaseName: "DeleteOrderByIdAsync_PositiveAndNegative_TestAsync") .Options; using (var context = new ApartmentContext(options)) { Country country = new Country() { Name = "Litva" }; context.Add(country); context.AddRange(_users); await context.SaveChangesAsync(); User userWithOrders = context.Users.AsNoTracking().FirstOrDefault(); foreach (var item in _addresses) { item.CountryId = context.Countries.FirstOrDefault().Id; } for (int i = 0; i < 2; i++) { _apartments[i].OwnerId = userWithOrders.Id; _apartments[i].Address = _addresses[i]; } context.AddRange(_apartments); await context.SaveChangesAsync(); Apartment apartmentWithOrders = context.Apartments.AsNoTracking().FirstOrDefault(); Order order = new Order() { ApartmentId = apartmentWithOrders.Id, CustomerId = userWithOrders.Id, }; List <BusyDate> busyDates = new List <BusyDate>(); BusyDate date = new BusyDate() { ApartmentId = apartmentWithOrders.Id, Date = DateTime.Now.Date }; busyDates.Add(date); order.Dates = _mapper.Map <HashSet <BusyDate> >(busyDates); context.AddRange(order); await context.SaveChangesAsync(); } using (var context = new ApartmentContext(options)) { var orderInBase = await context.Orders.AsNoTracking().FirstOrDefaultAsync(); var service = new OrderUserService(context, _mapper); var resultPositive = await service.DeleteOrderByIdAsync(orderInBase.Id.ToString(), orderInBase.CustomerId.ToString()); var resultNegative = await service.DeleteOrderByIdAsync(new Guid().ToString(), new Guid().ToString()); resultPositive.IsSuccess.Should().BeTrue(); resultPositive.Message.Should().BeNull(); resultNegative.IsSuccess.Should().BeFalse(); resultNegative.Message.Should().Contain("not found"); } }
public async void GetAllOrdersByApartmentIdAsync_PositiveAndNegative_TestAsync() { var options = new DbContextOptionsBuilder <ApartmentContext>() .UseInMemoryDatabase(databaseName: "GetAllOrdersByApartmentIdAsync_PositiveAndNegative_TestAsync") .Options; Apartment apartmentWithOrders; using (var context = new ApartmentContext(options)) { Country country = new Country() { Name = "Litva" }; context.Add(country); context.AddRange(_users); await context.SaveChangesAsync(); User userWithOrders = context.Users.AsNoTracking().FirstOrDefault(); foreach (var item in _addresses) { item.CountryId = context.Countries.FirstOrDefault().Id; } for (int i = 0; i < 2; i++) { _apartments[i].OwnerId = userWithOrders.Id; _apartments[i].Address = _addresses[i]; } context.AddRange(_apartments); await context.SaveChangesAsync(); apartmentWithOrders = context.Apartments.AsNoTracking().FirstOrDefault(); Order order = new Order() { ApartmentId = apartmentWithOrders.Id, CustomerId = userWithOrders.Id, }; List <BusyDate> busyDates = new List <BusyDate>(); BusyDate date = new BusyDate() { ApartmentId = apartmentWithOrders.Id, Date = DateTime.Now.Date }; busyDates.Add(date); order.Dates = _mapper.Map <HashSet <BusyDate> >(busyDates); context.AddRange(order); await context.SaveChangesAsync(); } using (var context = new ApartmentContext(options)) { var service = new OrderUserService(context, _mapper); var ordersInBase = await context.Orders.AsNoTracking().ToListAsync(); var apartmentWithoutOrders = await context.Users.Where(_ => _.Id != apartmentWithOrders.Id).FirstOrDefaultAsync(); var resultPositive = await service.GetAllOrdersByApartmentIdAsync(new Common.PagedRequest <string>(apartmentWithOrders.Id.ToString())); var resultNegative = await service.GetAllOrdersByApartmentIdAsync(new Common.PagedRequest <string>(apartmentWithoutOrders.Id.ToString())); foreach (var item in ordersInBase) { resultPositive.Data.Data.FirstOrDefault() .ApartmentId .Should().BeEquivalentTo(item.ApartmentId.ToString()); } resultNegative.Data.Data.Should().BeEmpty(); } }