public void ServantByIdSuccess()
        {
            var mockRepo      = new Mock <IServantRepository>();
            var mockDbContext = new Mock <IDbContext>();

            var servant = new Servant()
            {
                Id    = 1,
                Name  = "MockedServant",
                Title = "MockServantTitle",
                FirstAscensionImage = "MockFirstAscImage",
                FinalAscensionImage = "MockFinalAscImage",
                Dialogue            = "MockDialogue",
                Audio = "MockAudio"
            };

            mockRepo.Setup(repo => repo.GetServantByIdAsync(1)).ReturnsAsync(servant);
            mockDbContext.Setup(db => db.Servants).Returns(mockRepo.Object);

            var sut    = new ServantController(mockDbContext.Object);
            var result = sut.ServantById(1).Result.Value;

            Assert.AreEqual(servant.Id, result.Id);
            Assert.AreEqual(servant.Title, result.Title);
            Assert.AreEqual(servant.FinalAscensionImage, result.FinalAscensionImage);
        }
Beispiel #2
0
        public void GetServant_ShouldReturnServant_WhenServantIsFoundInRepository()
        {
            var id = 1;

            MockRepo.Setup(repo => repo.GetServantById(id)).Returns <int>(m => new Servant());

            var controller = new ServantController(MockRepo.Object, MockServantCreationValidator.Object);

            Assert.IsInstanceOf <Servant>(controller.GetServantById(id));
        }
Beispiel #3
0
        public void GetServantById_ShouldReturnNoContentResult_WhenServantIsNull()
        {
            var id = 1;

            MockRepo.Setup(repo => repo.GetServantById(id)).Returns <int>(sId => null);

            var controller = new ServantController(MockRepo.Object, MockServantCreationValidator.Object);

            Assert.IsInstanceOf <NoContentResult>(controller.GetServantById(id));
        }
Beispiel #4
0
        public void SaveServant_ShouldReturnOkResult_WhenTheServantIsValid()
        {
            var servant = new Servant();

            MockRepo.Setup(repo => repo.SaveServant(servant)).Verifiable();
            MockServantCreationValidator.Setup(mscv => mscv.Validate(It.IsAny <CreationCandidate <Servant> >())).Returns(new ValidationResult());

            var controller = new ServantController(MockRepo.Object, MockServantCreationValidator.Object);

            Assert.IsInstanceOf <OkObjectResult>(controller.SaveServant(servant));
        }
Beispiel #5
0
        public void SaveServant_ShouldReturnErrors_WhenTheServantIsInvalid()
        {
            var servant = new Servant();

            servant.Strength = 1000;

            MockRepo.Setup(repo => repo.SaveServant(servant)).Verifiable();
            var realServantCreationValidator = new ServantCreationValidator();

            var controller = new ServantController(MockRepo.Object, realServantCreationValidator);

            Assert.IsInstanceOf <IList <ValidationFailure> >(controller.SaveServant(servant));
        }
        public void ServantByIdFail()
        {
            var mockRepo      = new Mock <IServantRepository>();
            var mockDbContext = new Mock <IDbContext>();

            Servant servant = null;

            mockRepo.Setup(repo => repo.GetServantByIdAsync(-1)).ReturnsAsync(servant);
            mockDbContext.Setup(db => db.Servants).Returns(mockRepo.Object);

            var sut    = new ServantController(mockDbContext.Object);
            var result = sut.ServantById(-1).Result.Value;

            Assert.IsNull(result);
        }