public void DeletedAssignmentShoundNotExistInDatabase()
        {
            //Arrange
            NewAssignmentVm assignmentToAdd = new NewAssignmentVm()
            {
                Id   = 1,
                Name = "test"
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var assignmentService = new AssignmentService(mapper, new AssignmentRepository(context));
                var result            = assignmentService.AddAssignment(assignmentToAdd);
                assignmentService.DeleteAssignment(1);
                var deletedAssignment = assignmentService.GetAssignmentDetails(1);

                //Assert
                deletedAssignment.Should().BeNull();
            }
        }
Example #2
0
        public void CheckAssignmentIdAfterAdd()
        {
            //Arrange
            NewAssignmentVm assignmentToAdd = new NewAssignmentVm()
            {
                Id   = 6,
                Name = "test",
            };

            Assignment assignment = new Assignment()
            {
                Id   = 6,
                Name = "test"
            };

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            var mock = new Mock <IAssignmentRepository>();

            mock.Setup(s => s.AddAssignment(assignment)).Returns(assignment.Id);

            var manager = new AssignmentService(mapper, mock.Object);

            //Act
            var result = manager.AddAssignment(assignmentToAdd);

            //Assert
            result.Should().Equals(assignment.Id);
        }
        public void CheckAssignmentIfExistAfterAdd()
        {
            //Arrange
            NewAssignmentVm assignmentToAdd = new NewAssignmentVm()
            {
                Id   = 1,
                Name = "test"
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var assignmentService = new AssignmentService(mapper, new AssignmentRepository(context));
                var result            = assignmentService.AddAssignment(assignmentToAdd);

                //Assert
                context.Assignments.FirstOrDefaultAsync(e => e.Id == result).Should().NotBeNull();
            }
        }
        public void CheckAssignmentToEditDetailsAreEqualLikeModel()
        {
            //Arrange
            NewAssignmentVm assignmentToAdd = new NewAssignmentVm()
            {
                Id   = 1,
                Name = "test"
            };

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;


            using (var context = new Context(options))
            {
                //Act
                var assignmentService = new AssignmentService(mapper, new AssignmentRepository(context));
                assignmentService.AddAssignment(assignmentToAdd);
                var result = assignmentService.GetAssignmentForEdit(1);

                //Assert
                result.Should().NotBeNull();
                result.Should().Equals(assignmentToAdd);
                context.Employers.FirstOrDefaultAsync(e => e.Id == result.Id).Should().NotBeNull();
            }
        }
        public async Task <IActionResult> Create(AssignmentCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Validation not passed!");
                return(View(model));
            }

            await _assignmentService.AddAssignment(model);

            return(RedirectToAction("Index"));
        }
        public void CheckAssignmentListExistAndIncludesProperData()
        {
            //Arrange
            NewAssignmentVm assignment1 = new NewAssignmentVm()
            {
                Id   = 1,
                Name = "test"
            };

            NewAssignmentVm assignment2 = new NewAssignmentVm()
            {
                Id   = 2,
                Name = "test1"
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var assignmentService = new AssignmentService(mapper, new AssignmentRepository(context));
                assignmentService.AddAssignment(assignment1);
                assignmentService.AddAssignment(assignment2);
                var listOfAssignments = assignmentService.GetAllActiveAssignmentsForList(2, 1, "");

                //Assert
                listOfAssignments.Should().NotBeNull();
                listOfAssignments.Assignments.Count.Should().Be(2);
                listOfAssignments.Assignments.Find(e => e.Id == 1).Should().Equals(assignment1);
                listOfAssignments.Assignments.Find(e => e.Id == 2).Should().Equals(assignment2);
            }
        }
        public HttpResponseMessage AddAssignment(AssignmentAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            ItemResponse <int> response = new ItemResponse <int>();

            response.Item = AssignmentService.AddAssignment(model);

            return(Request.CreateResponse(response));
        }
        public void UpdatedAssignmentShoundBeLikeAssignmentToUpdate()
        {
            //Arrange
            NewAssignmentVm assignment = new NewAssignmentVm()
            {
                Id   = 1,
                Name = "test"
            };

            List <int> listOfTagsIds = new List <int> {
                1, 2
            };

            NewAssignmentVm assignmentToUpdate = new NewAssignmentVm()
            {
                Id     = 1,
                Name   = "test1",
                TagsId = listOfTagsIds
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var assignmentService = new AssignmentService(mapper, new AssignmentRepository(context));
                assignmentService.AddAssignment(assignment);
            }

            using (var context = new Context(options))
            {
                var assignmentService = new AssignmentService(mapper, new AssignmentRepository(context));
                assignmentService.UpdateAssignment(assignmentToUpdate);

                //Assert
                context.Assignments.FirstOrDefaultAsync(e => e.Id == 1).Should().Equals(assignmentToUpdate);
            }
        }