Beispiel #1
0
        public void DeleteFavoriteMission_Validation_Test(int id, bool exists, int expected)
        {
            //Arrange
            User dbUser = new User
            {
                UserId   = 1,
                UserName = "******",
                Password = "******",
                EMail    = "*****@*****.**"
            };
            Mission dbMission = new Mission
            {
                Created     = new DateTime(2020, 8, 5),
                Description = "Project1 for DHL",
                Finished    = null,
                MissionName = "DHL Project1",
                Color       = "#F0D87B",
                Start       = new DateTime(2020, 8, 6),
                Status      = 1,
                UserId      = 1,
                CustomerId  = 1
            };

            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 <IFavoriteMissionRepository> favortieRepoMock = new Mock <IFavoriteMissionRepository>();

            favortieRepoMock.Setup(f => f.Delete(It.IsAny <User>(), It.IsAny <FavoriteMission>()));
            favortieRepoMock.Setup(f => f.Update(It.IsAny <FavoriteMission>()));
            favortieRepoMock.Setup(f => f.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.FavoriteMissionRepository).Returns(favortieRepoMock.Object);

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

            //Act
            var result = controller.DeleteFavoriteMission(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);
            }
        }