Пример #1
0
        public void Return_Correct_Edited_Type()
        {
            var options = Utils.GetOptions(nameof(Return_Correct_Edited_Type));

            var beerType = new BeerType
            {
                Id          = 1,
                Description = "Type of beer conditioned at low temperatures.",
                Type        = "Lager",
            };

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.BeerTypes.Add(beerType);
                arrangeContext.SaveChanges();
            }

            var newType  = "Lageerr";
            var newDescr = "Updated";

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new BeerTypesService(assertContext);

                var result = sut.UpdateBeerType(beerType.Id, newType, newDescr);

                Assert.AreEqual(beerType.Id, result.Id);
                Assert.AreEqual(newType, result.Type);
                Assert.AreEqual(newDescr, result.Description);
            }
        }
Пример #2
0
        public void Throw_When_TypeNotFound()
        {
            var options = Utils.GetOptions(nameof(Throw_When_TypeNotFound));

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new BeerTypesService(assertContext);

                Assert.ThrowsException <ArgumentNullException>(() => sut.GetBeerType(1));
            }
        }
Пример #3
0
        public void ReturnCorrectResult(string searchPattern, int expectedCount)
        {
            // Arrange
            var allTypes = new List <BeerType>();

            for (var i = 0; i < expectedCount; i++)
            {
                var beerTypeName = this.Fixture.Create <string>() + searchPattern + this.Fixture.Create <string>();
                allTypes.Add(new BeerType()
                {
                    Type = beerTypeName
                });
            }

            for (var i = 0; i < expectedCount / 2; i++)
            {
                var beerTypeName = this.Fixture.Create <string>();
                allTypes.Add(new BeerType()
                {
                    Type = beerTypeName
                });
            }

            var repository = new Mock <IEfRepository <BeerType> >();

            repository.Setup(r => r.All)
            .Returns(allTypes.AsQueryable);
            var sut = new BeerTypesService(repository.Object);

            // Act
            var result = sut.Search(searchPattern);

            // Assert
            var actual = result as IList <IBeerType> ?? result.ToList();

            Assert.AreEqual(expectedCount, actual.Count);
            foreach (var beerType in actual)
            {
                StringAssert.Contains(searchPattern, beerType.Type);
            }
        }
Пример #4
0
        public void Create_Correct_BeerType()
        {
            var options  = Utils.GetOptions(nameof(Create_Correct_BeerType));
            var beerType = new BeerType
            {
                Id          = 1,
                Description = "Type of beer conditioned at low temperatures.",
                Type        = "Lager",
            };

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                var sut         = new BeerTypesService(arrangeContext);
                var beerTypeDTO = new BeerTypeDTO(beerType.Id, beerType.Type, beerType.Description);
                var result      = sut.CreateBeerType(beerTypeDTO);

                Assert.AreEqual(beerType.Id, result.Id);
                Assert.AreEqual(beerType.Type, result.Type);
                Assert.AreEqual(beerType.Description, result.Description);
            }
        }
Пример #5
0
        public void ReturnTrue_When_TypeIsDeleted()
        {
            var options  = Utils.GetOptions(nameof(ReturnTrue_When_TypeIsDeleted));
            var beerType = new BeerType
            {
                Id          = 1,
                Description = "Type of beer conditioned at low temperatures.",
                Type        = "Lager",
            };

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.BeerTypes.Add(beerType);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new BeerTypesService(assertContext);
                var result = sut.DeleteBeerType(1);

                Assert.IsTrue(result);
            }
        }
Пример #6
0
        public void Return_Correct_Types()
        {
            var options = Utils.GetOptions(nameof(Return_Correct_Types));

            var beerType1 = new BeerType
            {
                Id          = 1,
                Description = "Type of beer conditioned at low temperatures.",
                Type        = "Lager",
            };

            var beerType2 = new BeerType
            {
                Id          = 2,
                Description = "Type of beer brewed using a warm fermentation method",
                Type        = "Ale",
            };

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.BeerTypes.Add(beerType1);
                arrangeContext.BeerTypes.Add(beerType2);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new BeerTypesService(assertContext);

                var result = sut.GetAllBeerTypes().First();

                Assert.AreEqual(beerType1.Id, result.Id);
                Assert.AreEqual(beerType1.Type, result.Type);
                Assert.AreEqual(beerType1.Description, result.Description);
            }
        }