Exemplo n.º 1
0
        public void Create_Throws_Exception_If_Program_Has_Id_Not_Equal_To_0()
        {
            //arrange
            var program = new Program() { Id = 1 };
            var exceptionWasThrown = false;

            //act
            var logic = new ProgramLogic();
            try
            {
                var result = logic.Create(program);
            }
            catch (ValidationException)
            {
                exceptionWasThrown = true;
            }

            //assert
            Assert.IsTrue(exceptionWasThrown, "Create should have thrown an exception");
        }
Exemplo n.º 2
0
        public void Create_Returns_Object_With_Id_On_Success()
        {
            //arrange
            var program = new Program();
            var mockRepo = new Mock<IRemoteEntities>();
            var dbSet = new FakeDbSet<Program>();
            mockRepo.SetupGet(m => m.Programs)
                    .Returns(dbSet);

            DataFactory.Set(mockRepo.Object);

            //act
            var logic = new ProgramLogic();
            var result = logic.Create(program);

            //assert
            Assert.AreEqual(1, dbSet.Count(), "No items were saved to the db");
            Assert.AreEqual(dbSet.First(), result, "The item returned was not the same as the one in the database");
            mockRepo.Verify(m => m.SaveChanges(), Times.Once(), "The changes were not saved to the database");
        }