Ejemplo n.º 1
0
        public void AddMissionMember_Validation_Test(int id, bool exists, int expected)
        {
            //Arrange
            User dbUser = new User
            {
                UserId   = 1,
                UserName = "******",
                Password = "******",
                EMail    = "*****@*****.**"
            };

            Mock <IUserRepository> userRepoMock = new Mock <IUserRepository>();

            userRepoMock.Setup(u => u.GetById(It.IsAny <int>())).Returns(dbUser);
            Mock <IMissionRepository> missionRepoMock = new Mock <IMissionRepository>();

            missionRepoMock.Setup(r => r.Exists(It.IsAny <int>())).Returns(exists);

            Mock <IMissionMemberRepository> missionMemberRepoMock = new Mock <IMissionMemberRepository>();

            missionMemberRepoMock.Setup(r => r.Insert(It.IsAny <MissionMember>()));
            missionMemberRepoMock.Setup(r => r.Update(It.IsAny <MissionMember>()));
            missionMemberRepoMock.Setup(r => r.Save());

            Mock <IUnitOfWork> mockUOF = new Mock <IUnitOfWork>();

            mockUOF.Setup(uow => uow.UserRepository).Returns(userRepoMock.Object);
            mockUOF.Setup(uow => uow.MissionRepository).Returns(missionRepoMock.Object);
            mockUOF.Setup(uow => uow.MissionMemberRepository).Returns(missionMemberRepoMock.Object);

            var controller = new MissionController(mockUOF.Object, httpContextAccessorMock);

            //Act
            var result = controller.AddMissionMember(id);

            //Assert
            Assert.IsType <ActionResult <HttpResponse> >(result);
            if (expected == StatusCodes.Status400BadRequest)
            {
                Assert.Equal(expected, (result.Result as ObjectResult).StatusCode);
            }
            else
            {
                Assert.Equal(expected, (result.Result as StatusCodeResult).StatusCode);
            }
        }