public async void CreateCommentAsync_Positive_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "CreateCommentAsync_PositiveAndNegative_TestAsync")
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                context.AddRange(_users);
                context.AddRange(_apartments);

                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var user      = context.Users.AsNoTracking().FirstOrDefault();;
                var apartment = context.Apartments.AsNoTracking().FirstOrDefault();;

                AddComment comment = new AddComment()
                {
                    ApartmentId = apartment.Id.ToString(),
                    Title       = "Title",
                    Text        = "Text"
                };

                var service = new CommentUserService(context, _mapper);

                var resultPositive = await service.CreateCommentAsync(comment, user.Id.ToString());

                resultPositive.IsSuccess.Should().BeTrue();
                resultPositive.Data.Title.Should().BeEquivalentTo(comment.Title);
            }
        }
        public async void CreateOrderAsync_Positive_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "CreateOrderAsync_PositiveAndNegative_TestAsync")
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                context.AddRange(_users);
                await context.SaveChangesAsync();

                User userWithApartments = 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 = userWithApartments.Id;
                    _apartments[i].Address = _addresses[i];
                }

                context.AddRange(_apartments);
                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var service = new OrderUserService(context, _mapper);

                var user      = context.Users.AsNoTracking().FirstOrDefault();;
                var apartment = context.Apartments.AsNoTracking().FirstOrDefault();;

                IEnumerable <DateTime> dateTimes = new List <DateTime>()
                {
                    DateTime.Now.Date
                };

                AddOrder order = new AddOrder()
                {
                    ApartmentId = apartment.Id.ToString(),
                    Dates       = dateTimes
                };

                var resultPositive = await service.CreateOrderAsync(order, user.Id.ToString());

                resultPositive.IsSuccess.Should().BeTrue();
                resultPositive.Data.Apartment.Title.Should().BeEquivalentTo(apartment.Title);
                resultPositive.Data.Order.Dates.FirstOrDefault().Should().BeSameDateAs(dateTimes.First());

                context.BusyDates.FirstOrDefault().Date.Should().BeSameDateAs(dateTimes.First());
            }
        }
Ejemplo n.º 3
0
        public async void GetAllApartmentByUserIdAsync_PositiveAndNegative_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "GetAllApartmentByUserIdAsync_PositiveAndNegative_TestAsync")
                          .Options;

            User userWithApartments;

            using (var context = new ApartmentContext(options))
            {
                context.AddRange(_users);
                await context.SaveChangesAsync();

                userWithApartments = 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 = userWithApartments.Id;
                    _apartments[i].Address = _addresses[i];
                }

                context.AddRange(_apartments);
                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var service = new ApartmentUserService(context, _mapper);

                var apartmentsInBase = await context.Apartments.AsNoTracking().ToListAsync();

                var userWithoutApartments = await context.Users.Where(_ => _.Id != userWithApartments.Id).FirstOrDefaultAsync();

                var resultPositive = await service.GetAllApartmentByOwnerIdAsync(userWithApartments.Id.ToString(), new Common.PagedRequest());

                var resultNegative = await service.GetAllApartmentByOwnerIdAsync(userWithoutApartments.Id.ToString(), new Common.PagedRequest());

                foreach (var item in apartmentsInBase)
                {
                    resultPositive.Data.Data
                    .Where(_ => _.Apartment.Id == item.Id.ToString())
                    .FirstOrDefault()
                    .Should().NotBeNull();
                }

                resultNegative.Data.Data.Should().BeEmpty();
            }
        }
Ejemplo n.º 4
0
        public async void DeleteUserProfileByIdentityIdAsync_PositiveAndNegative_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteUserProfileByIdentityIdAsync_PositiveAndNegative_TestAsync")
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                context.AddRange(_users);
                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var user = await context.Users.AsNoTracking().FirstOrDefaultAsync();

                var service = new UserAdministrationService(context, _mapper);

                var resultPositive = await service.DeleteUserProfileByIdentityIdAsync(user.Id.ToString());

                var resultNegative = await service.DeleteUserProfileByIdentityIdAsync(new Guid().ToString());

                resultPositive.IsSuccess.Should().BeTrue();
                resultPositive.Message.Should().BeNull();

                resultNegative.IsSuccess.Should().BeFalse();
                resultNegative.Message.Should().Contain("not exist");
            }
        }
        public async void GetCommentByIdAsync_PositiveAndNegative_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "GetCommentByIdAsync_PositiveAndNegative_TestAsync")
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                context.AddRange(_comments);
                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var comment = await context.Comments.AsNoTracking().FirstOrDefaultAsync();

                var service = new CommentAdministrationService(context, _mapper);

                var resultPositive = await service.GetCommentByIdAsync(comment.Id.ToString());

                var resultNegative = await service.GetCommentByIdAsync(new Guid().ToString());

                resultPositive.IsSuccess.Should().BeTrue();
                resultPositive.Data.Title.Should().BeEquivalentTo(comment.Title);

                resultNegative.IsSuccess.Should().BeFalse();
                resultNegative.Data.Should().BeNull();
            }
        }
        public async void DeleteCommentByIdAsync_PositiveAndNegative_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteCommentByIdAsync_PositiveAndNegative_TestAsync")
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                foreach (var item in _comments)
                {
                    item.AuthorId = Guid.NewGuid();
                }

                context.AddRange(_comments);
                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var comment = await context.Comments.AsNoTracking().FirstOrDefaultAsync();

                var service = new CommentUserService(context, _mapper);

                var resultPositive = await service.DeleteCommentByIdAsync(comment.Id.ToString(), comment.AuthorId.ToString());

                var resultNegative = await service.DeleteCommentByIdAsync(new Guid().ToString(), new Guid().ToString());

                resultPositive.IsSuccess.Should().BeTrue();
                resultPositive.Message.Should().BeNull();

                resultNegative.IsSuccess.Should().BeFalse();
                resultNegative.Message.Should().Contain("Comment was not found");
            }
        }
Ejemplo n.º 7
0
        public async void GetApartmentByIdAsync_PositiveAndNegative_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "GetApartmentByIdAsync_PositiveAndNegative_TestAsync")
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                context.AddRange(_users);
                await context.SaveChangesAsync();

                var userWithApartments = 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 = userWithApartments.Id;
                    _apartments[i].Address = _addresses[i];
                }

                context.AddRange(_apartments);
                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var apartment = await context.Apartments.AsNoTracking()
                                .Include(_ => _.Address.Country).FirstOrDefaultAsync();

                var service = new ApartmentUserService(context, _mapper);

                var resultPositive = await service.GetApartmentByIdAsync(apartment.Id.ToString());

                var resultNegative = await service.GetApartmentByIdAsync(new Guid().ToString());

                resultPositive.IsSuccess.Should().BeTrue();
                resultPositive.Data.Apartment.Title.Should().BeEquivalentTo(apartment.Title);
                resultPositive.Data.Country.Name.Should().BeEquivalentTo(apartment.Address.Country.Name);

                resultNegative.IsSuccess.Should().BeFalse();
                resultNegative.Data.Should().BeNull();
            }
        }
        public async void GetAllCommentsByApartmentIdAsync_PositiveAndNegative_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "GetAllCommentsByApartmentIdAsync_PositiveAndNegative_TestAsync")
                          .Options;

            Apartment apartmentWithComments;

            using (var context = new ApartmentContext(options))
            {
                context.AddRange(_apartments);
                await context.SaveChangesAsync();

                apartmentWithComments = context.Apartments.AsNoTracking().FirstOrDefault();

                foreach (var item in _comments)
                {
                    item.ApartmentId = apartmentWithComments.Id;
                }

                context.AddRange(_comments);
                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var service = new CommentAdministrationService(context, _mapper);

                var commentsInBase = await context.Comments.AsNoTracking().ToListAsync();

                var apartmentWithoutComments = context.Apartments.Where(_ => _.Id != apartmentWithComments.Id).FirstOrDefault();

                var resultPositive = await service.GetAllCommentsByApartmentIdAsync(new PagedRequest <string>(apartmentWithComments.Id.ToString()));

                var resultNegative = await service.GetAllCommentsByApartmentIdAsync(new PagedRequest <string>(apartmentWithoutComments.Id.ToString()));

                foreach (var item in commentsInBase)
                {
                    resultPositive.Data.Data
                    .Where(_ => _.Id == item.Id.ToString())
                    .FirstOrDefault()
                    .Should().NotBeNull();
                }

                resultNegative.Data.Data.Should().BeEmpty();
            }
        }
Ejemplo n.º 9
0
        public async void CreateApartmentAsync_Positive_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "CreateApartmentAsync_PositiveAndNegative_TestAsync")
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                context.AddRange(_users);
                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var service = new ApartmentUserService(context, _mapper);

                User user = await context.Users.FirstOrDefaultAsync();

                AddAddress address = new AddAddress()
                {
                    CountryId         = context.Countries.FirstOrDefault().Id.ToString(),
                    City              = "MyCity",
                    Street            = "Street",
                    Home              = "Home",
                    NumberOfApartment = 1
                };

                AddApartment apartmentOk = new AddApartment()
                {
                    Address       = address,
                    Area          = 54,
                    IsOpen        = true,
                    Price         = 15M,
                    Title         = "Apartment",
                    Text          = "AddedApartment",
                    NumberOfRooms = 2
                };

                var resultPositive = await service.CreateApartmentAsync(apartmentOk, user.Id.ToString());

                resultPositive.IsSuccess.Should().BeTrue();
                resultPositive.Data.Country.Id.Should().BeEquivalentTo(address.CountryId);
                resultPositive.Data.Address.Street.Should().BeEquivalentTo(address.Street);
                resultPositive.Data.Apartment.Title.Should().BeEquivalentTo(apartmentOk.Title);
            }
        }
        public async void UpdateCommentAsync_PositiveAndNegative_TestAsync()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: "UpdateCommentAsync_PositiveAndNegative_TestAsync")
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                context.AddRange(_comments);
                await context.SaveChangesAsync();
            }

            using (var context = new ApartmentContext(options))
            {
                var comment = await context.Comments.AsNoTracking().FirstOrDefaultAsync();

                var service = new CommentAdministrationService(context, _mapper);

                CommentDTOAdministration updateComment = new CommentDTOAdministration()
                {
                    Id    = comment.Id.ToString(),
                    Title = "newTitle",
                    Text  = "newText"
                };

                CommentDTOAdministration failComment = new CommentDTOAdministration()
                {
                    Id    = new Guid().ToString(),
                    Title = "newTitle",
                    Text  = "newText"
                };

                var resultPositive = await service.UpdateCommentAsync(updateComment);

                var resultNegative = await service.UpdateCommentAsync(failComment);

                resultPositive.IsSuccess.Should().BeTrue();
                resultPositive.Data.Title.Should().BeEquivalentTo(updateComment.Title);
                resultPositive.Data.Title.Should().NotBeEquivalentTo(comment.Title);

                resultNegative.IsSuccess.Should().BeFalse();
            }
        }
        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 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 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();
            }
        }