Beispiel #1
0
        public void ReturnViewWithFirstModelInProvidedCollectionWhenParameterIdIsNull()
        {
            // Arrange
            var      creatureServiceMock = new Mock <ICreatureService>();
            Creature firstCreature       = new Creature()
            {
                Name = "GoldFish", Id = 1
            };
            Creature secondCreature = new Creature()
            {
                Name = "ClownFish", Id = 2
            };
            var listOfCreatures = new List <Creature>()
            {
                firstCreature, secondCreature
            };

            creatureServiceMock.Setup(x => x.GetAllCreatures()).Returns(listOfCreatures.AsQueryable);

            // Act
            var creatureController = new AquaWorld.Web.Controllers.CreaturesController(creatureServiceMock.Object);

            //Assert
            creatureController
            .WithCallTo(c => c.Details(null))
            .ShouldRenderDefaultView()
            .WithModel <Creature>(model =>
            {
                Assert.IsInstanceOf(typeof(Creature), model);
                Assert.AreEqual(model, firstCreature);
            });
        }
Beispiel #2
0
        public void ReturnViewWithListOfCorrectModelsWhenThereAreAnyExisting()
        {
            // Arrange
            var      creatureServiceMock = new Mock <ICreatureService>();
            Creature firstCreature       = new Creature()
            {
                Name = "GoldFish"
            };
            Creature secondCreature = new Creature()
            {
                Name = "ClownFish"
            };

            var listOfCreatures = new List <Creature>()
            {
                firstCreature, secondCreature
            };

            // Act
            var creatureController = new AquaWorld.Web.Controllers.CreaturesController(creatureServiceMock.Object);

            //Assert
            creatureController
            .WithCallTo(c => c.Index())
            .ShouldRenderDefaultView()
            .WithModel <IList <CreatureViewModel> >(model =>
            {
                Assert.IsInstanceOf(typeof(IList <CreatureViewModel>), model);
            });
        }