public async Task UpdateAsync_ShouldChangeNameOfStyleAndDescriptionAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("UpdateAsync_ShouldChangeNameOfStyleAndDescriptionAsync");

            using (var context = new BOContext(options))
            {
                var style = new BeerStyle()
                {
                    Name        = "Ale",
                    Description = "This description"
                };
                context.BeerStyles.Add(style);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                var styleDTO = new BeerStyleDTO()
                {
                    Name        = "Ale2",
                    Description = "This description2"
                };
                //Act
                var sut = new BeerStylesService(context);
                await sut.UpdateAsync(1, styleDTO);

                var dbresult = await context.BeerStyles.FindAsync(1);

                //Assert
                Assert.AreEqual(dbresult.Name, "Ale2");
                Assert.AreEqual(dbresult.Description, "This description2");
            }
        }
        public async Task CreateAsync_ShouldReturnModifiedBeerStyleDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("CreateAsync_ShouldReturnModifiedBeerStyleDTOAsync");

            using (var context = new BOContext(options))
            {
            }

            using (var context = new BOContext(options))
            {
                var styleDTO = new BeerStyleDTO()
                {
                    Name        = "Ale",
                    Description = "This description"
                };
                //Act
                var sut    = new BeerStylesService(context);
                var result = await sut.CreateAsync(styleDTO);

                var dbresult = await context.BeerStyles.FirstOrDefaultAsync(c => c.Name == "Ale");

                //Assert
                Assert.AreEqual(result.ID, dbresult.ID);
                Assert.AreEqual(result.Name, dbresult.Name);
            }
        }
        public async Task GetAllAsync_ShouldReturnIEnumerableBeerStyleDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllAsync_ShouldReturnIEnumerableBeerStyleDTOAsync");

            using (var context = new BOContext(options))
            {
                var style = new BeerStyle()
                {
                    Name        = "Ale",
                    Description = "This description"
                };
                context.BeerStyles.Add(style);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new BeerStylesService(context);
                var result = await sut.GetAllAsync();

                //Assert
                Assert.IsInstanceOfType(result, typeof(IEnumerable <BeerStyleDTO>));
            }
        }
Exemplo n.º 4
0
        public async Task UpdateAsync_ShouldReturnNullIfCommentNonExistantAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("UpdateAsync_ShouldReturnNullIfCommentNonExistantAsync");

            using (var context = new BOContext(options))
            {
            }

            using (var context = new BOContext(options))
            {
                var commentDTO = new CommentDTO
                {
                    Description = "Gotham",
                    User        = new UserDTO()
                    {
                        Name = "Batman"
                    },
                    Review = new ReviewDTO()
                    {
                        Description = "Description"
                    }
                };
                //Act
                var sut    = new CommentService(context);
                var result = await sut.UpdateAsync(1, commentDTO);

                //Assert
                Assert.AreEqual(result, null);
            }
        }
Exemplo n.º 5
0
        public async Task DeleteAsync_ShouldReturnTrueIfCommentSucceded()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldReturnTrueIfCommentSucceded");

            using (var context = new BOContext(options))
            {
                var comment = new Comment
                {
                    Description = "Gotham",
                    User        = new User()
                    {
                        Name = "Batman"
                    },
                    Review = new Review()
                    {
                        Description = "Description"
                    }
                };
                context.Comments.Add(comment);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new CommentService(context);
                var result = await sut.DeleteAsync(1);

                //Assert
                Assert.AreEqual(result, true);
            }
        }
Exemplo n.º 6
0
        public async Task CreateAsync_ShouldReturnCommentDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("CreateAsync_ShouldReturnCommentDTOAsync");

            using (var context = new BOContext(options))
            {
            }

            using (var context = new BOContext(options))
            {
                var commentDTO = new CommentDTO
                {
                    Description = "Gotham",
                    User        = new UserDTO()
                    {
                        Name = "Batman"
                    },
                    Review = new ReviewDTO()
                    {
                        Description = "Description"
                    }
                };
                //Act
                var sut    = new CommentService(context);
                var result = await sut.CreateAsync(commentDTO);

                //Assert
                Assert.IsInstanceOfType(result, typeof(CommentDTO));
            }
        }
Exemplo n.º 7
0
        public async Task CreateAsync_ShouldReturnModifiedCommentDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("CreateAsync_ShouldReturnModifiedCommentDTOAsync");

            using (var context = new BOContext(options))
            {
            }

            using (var context = new BOContext(options))
            {
                var commentDTO = new CommentDTO
                {
                    Description = "Gotham",
                    User        = new UserDTO()
                    {
                        Name = "Batman"
                    },
                    Review = new ReviewDTO()
                    {
                        Description = "Description"
                    }
                };
                //Act
                var sut    = new CommentService(context);
                var result = await sut.CreateAsync(commentDTO);

                var dbresult = await context.Comments.FindAsync(1);

                //Assert
                Assert.AreEqual(result.ID, dbresult.ID);
                Assert.AreEqual(result.Description, dbresult.Description);
            }
        }
Exemplo n.º 8
0
        public void GetAllUsersShould_ReturnCorrectUser()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllUsersShould_ReturnCorrectUser");

            using (var context = new BOContext(options))
            {
                var cut = new User()
                {
                    Id          = 1,
                    Name        = "SuperMan",
                    Password    = "******",
                    ReviewList  = new List <Review>(),
                    CommentList = new List <Comment>(),
                    DrankLists  = new List <DrankList>(),
                    WishLists   = new List <WishList>(),
                };
                context.Users.Add(cut);
                context.SaveChanges();
            }
            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new UsersService(context);
                var result = sut.GetAllUsers().Result.ToList();
                //Assert
                Assert.AreEqual(result.Count, 1);
                Assert.AreEqual(result[0].Name, "SuperMan");
            }
        }
Exemplo n.º 9
0
        public void DeleteUserShould_ReturnFalse_whenNotDeletedUser()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteUserShould_ReturnFalse_whenNotDeletedUser");

            using (var context = new BOContext(options))
            {
                var cut = new User()
                {
                    Id       = 1,
                    Name     = "SuperMan",
                    Password = "******",
                };

                context.Users.Add(cut);
                context.SaveChanges();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new UsersService(context);
                var result = sut.DeleteUser(55).Result;
                //Assert
                var deletedUsers = context.Users.Where(u => u.IsDeleted == true).Count();
                var activeUsers  = context.Users.Where(u => u.IsDeleted == false).Count();
                Assert.IsFalse(result);
                Assert.AreEqual(0, deletedUsers);
                Assert.AreEqual(1, activeUsers);
            }
        }
Exemplo n.º 10
0
        public async Task GetAllAsync_ShouldReturnNullBreweryIfModelHasNoNameAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllAsync_ShouldReturnNullBreweryIfModelHasNoNameAsync");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                    }
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new BreweryServices(context);
                var result = await sut.GetAllAsync();

                //Assert
                Assert.AreEqual(result, null);
            }
        }
        public async Task DeleteAsync_ShouldDeleteStyleIfExist()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldDeleteStyleIfExist");

            using (var context = new BOContext(options))
            {
                var style = new BeerStyle()
                {
                    Name        = "Ale",
                    Description = "This description"
                };
                context.BeerStyles.Add(style);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut = new BeerStylesService(context);
                await sut.DeleteAsync(1);

                var dbresult = await context.BeerStyles.FirstOrDefaultAsync(c => c.Name == "Ale");

                //Assert
                Assert.AreEqual(dbresult.Name, "Ale");
                Assert.AreEqual(dbresult.DeletedOn, dbresult.ModifiedOn);
                Assert.AreEqual(dbresult.IsDeleted, true);
            }
        }
Exemplo n.º 12
0
        public async Task CreateAsync_ShouldUndeleteRecordIfExist()
        {
            //Arrange
            var options = InMemory.GetOptions("CreateAsync_ShouldUndeleteRecordIfExist");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    DeletedOn = DateTime.UtcNow,
                    IsDeleted = true
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                var countryDTO = new CountryDTO()
                {
                    Name = "Bulgaria"
                };
                //Act
                var sut = new CountriesService(context);
                await sut.CreateAsync(countryDTO);

                var dbresult = await context.Countries.FirstOrDefaultAsync(c => c.Name == "Bulgaria");

                //Assert
                Assert.AreEqual(dbresult.Name, "Bulgaria");
                Assert.AreEqual(dbresult.DeletedOn, null);
                Assert.AreEqual(dbresult.IsDeleted, false);
            }
        }
Exemplo n.º 13
0
        public async Task GetAsync_ShouldReturnBreweryDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAsync_ShouldReturnBreweryDTOAsync");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                        {
                            Name  = "Brewery",
                            Beers = new List <Beer>()
                        }
                    }
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new BreweryServices(context);
                var result = await sut.GetAsync(1);

                //Assert
                Assert.IsInstanceOfType(result, typeof(BreweryDTO));;
            }
        }
Exemplo n.º 14
0
        public async Task UpdateAsync_ShouldReturnNullIfReviewNonExistantAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("UpdateAsync_ShouldReturnNullIfReviewNonExistantAsync");

            using (var context = new BOContext(options))
            {
            }

            using (var context = new BOContext(options))
            {
                var reviewDTO = new ReviewDTO
                {
                    Description = "Great",
                    Beer        = new BeerDTO()
                    {
                        Name = "Carlsberg"
                    },
                    User = new UserDTO()
                    {
                        Name = "SuperMan"
                    }
                };
                //Act
                var sut    = new ReviewsService(context);
                var result = await sut.UpdateAsync(1, reviewDTO);

                //Assert
                Assert.AreEqual(result, null);
            }
        }
Exemplo n.º 15
0
        public async Task DeleteAsync_ShouldReturnTrueIfSucceded()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldReturnTrueIfSucceded");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name = "Bulgaria"
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new CountriesService(context);
                var result = await sut.DeleteAsync(1);

                //Assert
                Assert.AreEqual(result, true);
            }
        }
        public async Task DeleteAsync_ShouldReturnTrueStyleIfSucceded()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldReturnTrueStyleIfSucceded");

            using (var context = new BOContext(options))
            {
                var style = new BeerStyle()
                {
                    Name        = "Ale",
                    Description = "This description"
                };
                context.BeerStyles.Add(style);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new BeerStylesService(context);
                var result = await sut.DeleteAsync(1);

                //Assert
                Assert.AreEqual(result, true);
            }
        }
Exemplo n.º 17
0
        public async Task UpdateAsync_ShouldChangeNameOfCountryAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("UpdateAsync_ShouldChangeNameOfCountryAsync");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name = "Bulgaria"
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                var countryDTO = new CountryDTO()
                {
                    Name = "Belgium"
                };
                //Act
                var sut    = new CountriesService(context);
                var result = await sut.UpdateAsync(1, countryDTO);

                var dbresult = await context.Countries.FindAsync(1);

                //Assert
                Assert.AreEqual(dbresult.Name, "Belgium");
            }
        }
Exemplo n.º 18
0
        public async Task DeleteAsync_ShouldDeleteCountryIfExist()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldDeleteCountryIfExist");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name = "Bulgaria"
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut = new CountriesService(context);
                await sut.DeleteAsync(1);

                var dbresult = await context.Countries.FirstOrDefaultAsync(c => c.Name == "Bulgaria");

                //Assert
                Assert.AreEqual(dbresult.Name, "Bulgaria");
                Assert.AreEqual(dbresult.DeletedOn, dbresult.ModifiedOn);
                Assert.AreEqual(dbresult.IsDeleted, true);
            }
        }
Exemplo n.º 19
0
        public async Task GetAllAsync_ShouldReturnIEnumerableCountryDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllAsync_ShouldReturnIEnumerableCountryDTOAsync");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name = "Bulgaria"
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new CountriesService(context);
                var result = await sut.GetAllAsync();

                //Assert
                Assert.IsInstanceOfType(result, typeof(IEnumerable <CountryDTO>));
            }
        }
Exemplo n.º 20
0
        public async Task CreateAsync_ShouldReturnModifiedCountryDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("CreateAsync_ShouldReturnModifiedCountryDTOAsync");

            using (var context = new BOContext(options))
            {
            }

            using (var context = new BOContext(options))
            {
                var countryDTO = new CountryDTO()
                {
                    Name = "Bulgaria"
                };
                //Act
                var sut    = new CountriesService(context);
                var result = await sut.CreateAsync(countryDTO);

                var dbresult = await context.Countries.FirstOrDefaultAsync(c => c.Name == "Bulgaria");

                //Assert
                Assert.AreEqual(result.ID, dbresult.ID);
                Assert.AreEqual(result.Name, dbresult.Name);
            }
        }
Exemplo n.º 21
0
        public async Task CreateAsync_ShouldRecordBreweryIfNotOnRecordAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("CreateAsync_ShouldRecordBreweryIfNotOnRecordAsync");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name = "Bulgaria"
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                var breweryDTO = new BreweryDTO()
                {
                    Name    = "Brewery",
                    Country = "Bulgaria"
                };
                //Act
                var sut = new BreweryServices(context);
                await sut.CreateAsync(breweryDTO);

                var dbresult = await context.Breweries.Include(b => b.Country).FirstOrDefaultAsync(c => c.Name == "Brewery");

                //Assert
                Assert.AreEqual(dbresult.Name, "Brewery");
            }
        }
Exemplo n.º 22
0
        public async Task DeleteAsync_ShouldReturnTrueIfReviewSucceded()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldReturnTrueIfSucceded");

            using (var context = new BOContext(options))
            {
                var review = new Review
                {
                    Description = "Great",
                    Beer        = new Beer()
                    {
                        Name = "Carlsberg"
                    },
                    User = new User()
                    {
                        Name = "SuperMan"
                    },
                };
                context.Reviews.Add(review);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new ReviewsService(context);
                var result = await sut.DeleteAsync(1);

                //Assert
                Assert.AreEqual(result, true);
            }
        }
Exemplo n.º 23
0
        public async Task GetAllAsync_ShouldReturnIEnumerableReviewDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllAsync_ShouldReturnIEnumerableReviewDTOAsync");

            using (var context = new BOContext(options))
            {
                var review = new Review
                {
                    Description = "Great",
                    Beer        = new Beer()
                    {
                        Name = "Carlsberg"
                    },
                    User = new User()
                    {
                        Name = "SuperMan"
                    }
                };
                context.Reviews.Add(review);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new ReviewsService(context);
                var result = await sut.GetAllAsync();

                //Assert
                Assert.IsInstanceOfType(result, typeof(IEnumerable <ReviewDTO>));
            }
        }
        public async Task DeleteAsync_ShouldDeleteRecordBeersOfStyleIfExist()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldDeleteRecordBeersOfStyleIfExist");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                        {
                            Name = "Brewery",
                        }
                    }
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();

                var beer = new Beer()
                {
                    Name    = "Carlsberg",
                    ABV     = 5,
                    Country = await context.Countries.FirstOrDefaultAsync(c => c.Name == "Bulgaria"),
                    Brewery = await context.Breweries.FirstOrDefaultAsync(b => b.Name == "Brewery"),
                    Style   = new BeerStyle()
                    {
                        Name        = "Ale",
                        Description = "Some description",
                    },
                    Rating = 5
                };
                context.Beers.Add(beer);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut = new BeerStylesService(context);
                await sut.DeleteAsync(1);

                var dbresult = await context.BeerStyles.FirstOrDefaultAsync(c => c.Name == "Ale");

                var dbBeerResult = await context.Beers.FirstOrDefaultAsync(b => b.StyleID == dbresult.ID);

                //Assert
                Assert.AreEqual(dbresult.Name, "Ale");
                Assert.AreEqual(dbresult.DeletedOn, dbresult.ModifiedOn);
                Assert.AreEqual(dbresult.IsDeleted, true);
                Assert.AreEqual(dbBeerResult.Name, "Carlsberg");
                Assert.AreEqual(dbBeerResult.DeletedOn, dbBeerResult.ModifiedOn);
                Assert.AreEqual(dbBeerResult.IsDeleted, true);
            }
        }
Exemplo n.º 25
0
        public async Task DeleteAsync_ShouldDeleteBeerIfExist()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldDeleteBeerIfExist");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                        {
                            Name  = "Brewery",
                            Beers = new List <Beer>()
                            {
                                new Beer()
                                {
                                    ABV     = 4.5f,
                                    Rating  = 2,
                                    Name    = "Carlsberg",
                                    Country = new Country()
                                    {
                                        Name = "Germany"
                                    },
                                    Style = new BeerStyle()
                                    {
                                        Name = "Ale"
                                    }
                                }
                            }
                        }
                    }
                };;
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut = new BeerService(context);
                await sut.DeleteAsync(1);

                var dbresult = await context.Beers.FirstOrDefaultAsync(c => c.Name == "Carlsberg");

                //Assert
                Assert.AreEqual(dbresult.Name, "Carlsberg");
                Assert.AreEqual(dbresult.DeletedOn, dbresult.ModifiedOn);
                Assert.AreEqual(dbresult.IsDeleted, true);
            }
        }
Exemplo n.º 26
0
        public async Task DeleteAsync_ShouldDeleteRecordCommentsIfExist()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldDeleteRecordCommentsIfExist");

            using (var context = new BOContext(options))
            {
                var review = new Review
                {
                    Description = "Great",
                    Beer        = new Beer()
                    {
                        Name = "Carlsberg"
                    },
                    User = new User()
                    {
                        Name = "SuperMan"
                    },
                    Comments = new List <Comment>()
                    {
                        new Comment()
                        {
                            Description = "Some description",
                            User        = new User()
                            {
                                Name = "Batman"
                            },
                        }
                    }
                };
                context.Reviews.Add(review);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut = new ReviewsService(context);
                await sut.DeleteAsync(1);

                var dbresult = await context.Reviews.FindAsync(1);

                var dbCommentResult = await context.Comments.FindAsync(1);

                //Assert
                Assert.AreEqual(dbresult.Description, "Great");
                Assert.AreEqual(dbresult.DeletedOn, dbresult.ModifiedOn);
                Assert.AreEqual(dbresult.IsDeleted, true);
                Assert.AreEqual(dbCommentResult.Description, "Some description");
                Assert.AreEqual(dbCommentResult.DeletedOn, dbCommentResult.ModifiedOn);
                Assert.AreEqual(dbCommentResult.IsDeleted, true);
            }
        }
Exemplo n.º 27
0
        public async Task GetAllAsync_ShouldReturnIEnumerableBeerDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllAsync_ShouldReturnIEnumerableBeerDTOAsync");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                        {
                            Name  = "Brewery",
                            Beers = new List <Beer>()
                            {
                                new Beer()
                                {
                                    ABV     = 4.5f,
                                    Rating  = 2,
                                    Name    = "Carlsberg",
                                    Country = new Country()
                                    {
                                        Name = "Germany"
                                    },
                                    Style = new BeerStyle()
                                    {
                                        Name = "Ale"
                                    }
                                }
                            }
                        }
                    }
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new BeerService(context);
                var result = await sut.GetAllAsync();

                //Assert
                Assert.IsInstanceOfType(result, typeof(IEnumerable <BeerDTO>));
            }
        }
Exemplo n.º 28
0
        public async Task DeleteAsync_ShouldReturnTrueIfBeerSucceded()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldReturnTrueIfBeerSucceded");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                        {
                            Name  = "Brewery",
                            Beers = new List <Beer>()
                            {
                                new Beer()
                                {
                                    ABV     = 4.5f,
                                    Rating  = 2,
                                    Name    = "Carlsberg",
                                    Country = new Country()
                                    {
                                        Name = "Germany"
                                    },
                                    Style = new BeerStyle()
                                    {
                                        Name = "Ale"
                                    }
                                }
                            }
                        }
                    }
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new BeerService(context);
                var result = await sut.DeleteAsync(1);

                //Assert
                Assert.AreEqual(result, true);
            }
        }
Exemplo n.º 29
0
        public async Task GetAllAsync_ShouldReturnNullBeerIfModelHasNoNameAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllAsync_ShouldReturnNullBeerIfModelHasNoNameAsync");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                        {
                            Name  = "Brewery",
                            Beers = new List <Beer>()
                            {
                                new Beer()
                                {
                                    ABV     = 4.5f,
                                    Rating  = 2,
                                    Country = new Country()
                                    {
                                        Name = "Germany"
                                    },
                                    Style = new BeerStyle()
                                    {
                                        Name = "Ale"
                                    }
                                }
                            }
                        }
                    }
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new BeerService(context);
                var result = await sut.GetAllAsync();

                //Assert
                Assert.AreEqual(result, null);
            }
        }
Exemplo n.º 30
0
        public async Task UpdateAsync_ShouldChangeDescriptionOfReviewAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("UpdateAsync_ShouldChangeDescriptionOfReviewAsync");

            using (var context = new BOContext(options))
            {
                var review = new Review
                {
                    Description = "Great",
                    Beer        = new Beer()
                    {
                        Name = "Carlsberg"
                    },
                    User = new User()
                    {
                        IDOld = 1, Name = "SuperMan"
                    },
                };
                context.Reviews.Add(review);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                var reviewDTO = new ReviewDTO
                {
                    Description = "Great2",
                    Beer        = new BeerDTO()
                    {
                        Name = "Carlsberg"
                    },
                    User = new UserDTO()
                    {
                        Name = "SuperMan"
                    }
                };
                //Act
                var sut = new ReviewsService(context);
                await sut.UpdateAsync(1, reviewDTO);

                var dbresult = await context.Reviews.FindAsync(1);

                //Assert
                Assert.AreEqual(dbresult.Description, "Great2");
            }
        }