Example #1
0
        public void HeroControllerGetCollectionTest()
        {
            // Arrange
            Hero[] expected = new[]
            {
                HeroTest.Create(),
                HeroTest.Create(),
            };
            
            Mock<IHeroRepository> heroRepositoryMock = new Mock<IHeroRepository>();
            heroRepositoryMock
                .Setup(r => r.Heroes)
                .Returns(expected);
                
            Mock<ICryptographyService> cryptographyServiceMock = new Mock<ICryptographyService>();

            // Act
            OkNegotiatedContentResult<HeroViewModel[]> actual = new HeroController(heroRepositoryMock.Object, cryptographyServiceMock.Object)
                .Get() as OkNegotiatedContentResult<HeroViewModel[]>;

            // Assert
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Content);
            Assert.AreEqual(expected.Length, actual.Content.Length);
        }
Example #2
0
        public void HeroControllerGetHeroTest()
        {
            // Arrange
            Hero expected = HeroTest.Create();

            Mock<IHeroRepository> heroRepositoryMock = new Mock<IHeroRepository>();
            heroRepositoryMock
                .Setup(r => r.GetHero(It.IsAny<Guid>()))
                .Returns(expected);

            Mock<ICryptographyService> cryptographyServiceMock = new Mock<ICryptographyService>();

            // Act
            OkNegotiatedContentResult<HeroViewModel> actual = new HeroController(heroRepositoryMock.Object, cryptographyServiceMock.Object)
                .Get("id") as OkNegotiatedContentResult<HeroViewModel>;

            // Assert
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Content);
            Assert.AreEqual(expected.Name, actual.Content.Name);
            Assert.AreEqual(expected.Type.Name, actual.Content.Type.Name);
            Assert.AreEqual(expected.Price, actual.Content.Price);
        }
Example #3
0
        public void HeroControllerPostTest()
        {
            // Arrange
            DateTime now = DateTime.Now;
            Hero expectedHero = HeroTest.Create();
            Hero actualHero = null;

            Mock<IHeroRepository> heroRepositoryMock = new Mock<IHeroRepository>();
            heroRepositoryMock
                .Setup(hr => hr.Save(It.IsAny<Hero>()))
                .Callback<Hero>(h => actualHero = h);
            heroRepositoryMock
                .Setup(hr => hr.HeroStates)
                .Returns(HeroRepository.Current.HeroStates); // Use the actual lookup values here

            Mock<ICryptographyService> cryptographyServiceMock = new Mock<ICryptographyService>();

            HeroPropertiesModel model = new HeroPropertiesModel(expectedHero.Name, expectedHero.Type, expectedHero.State, expectedHero.Price);

            // Act
            OkNegotiatedContentResult<HeroViewModel> actual =
                new HeroController(heroRepositoryMock.Object, cryptographyServiceMock.Object) {  Configuration = new HttpConfiguration() }
                    .Post(model) as OkNegotiatedContentResult<HeroViewModel>;

            // Assert
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Content);
            Assert.AreEqual(expectedHero.Name, actualHero.Name);
            Assert.AreEqual(expectedHero.Name, actual.Content.Name);
            Assert.AreEqual(expectedHero.Type, actualHero.Type);
            Assert.AreEqual(expectedHero.Price, actualHero.Price);
            Assert.AreEqual(expectedHero.Price, actual.Content.Price);
        }