コード例 #1
0
        public void GetById_Test()
        {
            // Arrange - Create the repository
            var repository = new RecipeRepository(_context);

            // Arrange - Setup expectations
            var expectedId = 1;

            // Act - Make the repository call
            repository.FullEagerLoad();
            var actual = repository.GetById(expectedId);

            // Assert - Verify the entity
            VerifyEntity(actual, expectedId);
        }
コード例 #2
0
        public void AddSingle_Test()
        {
            // Arrange - Create the repository
            var repository = new RecipeRepository(_context);

            // Arrange - Create the new recipe
            var sampleData = new SampleContext();
            var expected   = new Recipe {
                Name = "New Recipe One", Description = "Test New Description One", Category = (Category)sampleData.Categories.GetRandomEntity()
            };

            expected.Steps.Add(new Step {
                Description = "New Step One", SortOrder = 1
            });
            expected.Steps.Add(new Step {
                Description = "New Step Two", SortOrder = 2
            });
            expected.Ingredients.Add(new Ingredient {
                Unit = 1, Measurement = (Measurement)sampleData.Measurements.GetRandomEntity(), Product = (Product)sampleData.Products.GetRandomEntity(), SortOrder = 1
            });
            expected.Ingredients.Add(new Ingredient {
                Unit = 2, Measurement = (Measurement)sampleData.Measurements.GetRandomEntity(), Product = (Product)sampleData.Products.GetRandomEntity(), SortOrder = 2
            });

            // Arrange - Set the expected count
            var expectedRecipeCount = repository.GetAll().Count() + 1;

            // Act - Perform the repository call
            repository.Add(expected);
            _context.SaveChanges();

            // Assert - Check for the addition
            Assert.AreEqual(expectedRecipeCount, repository.GetAll().Count());

            // Verify the entity (gets by name as this should be unique in this test)
            repository.FullEagerLoad();
            var actual = repository.GetAll().SingleOrDefault(i => i.Name == expected.Name);

            Assert.IsNotNull(actual);
            CompareEntities(expected, actual);
        }
コード例 #3
0
        public void GetAll_Test()
        {
            // Arrange - Create the repository
            var repository = new RecipeRepository(_context);

            // Act - Set-up the repository call
            repository.FullEagerLoad();
            var actualList = repository.GetAll();

            // Assert - Check the result
            Assert.IsNotNull(actualList);
            Assert.IsTrue(actualList.Count() > 0);

            // Assert - Check the list count against the sample data.
            var sampleData = new SampleContext();

            Assert.AreEqual(actualList.Count(), sampleData.Recipes.Entities.Count());

            // Assert - Test the first recipe
            var recipe = actualList.First();

            VerifyEntity(recipe);
        }