Exemple #1
0
        public async Task PutScheduleThrowsDbUpdateExceptionTest()
        {
            // Arrange
            var mock    = new Mock <IUpdateEntry>();
            var entries = new List <IUpdateEntry>();

            entries.Add(mock.Object);

            int      testId     = 1;
            Schedule schedule   = GetTestSchedules().FirstOrDefault(p => p.Id == testId);
            var      mockLogger = new Mock <ILogger <SchedulesController> >();
            var      mockRepo   = new Mock <IVenuesRepository>();

            mockRepo.Setup(c => c.FirstSchedule(testId)).Returns(schedule);
            mockRepo.Setup(c => c.ChangeState(schedule, schedule, EntityState.Modified))
            .Verifiable();
            mockRepo.Setup(c => c.SaveChanges()).Throws(
                new DbUpdateConcurrencyException(It.IsNotNull <string>(), entries));
            mockRepo.Setup(c => c.ScheduleExists(testId)).Returns(true);
            var controller = new SchedulesController(mockRepo.Object, mockLogger.Object);

            // Act Assert
            await Assert.ThrowsAsync <DbUpdateConcurrencyException>(() =>
                                                                    controller.PutSchedule(schedule));
        }
Exemple #2
0
        public async Task PutScheduleReturnsBadRequestResultModelStateTest()
        {
            // Arrange & Act
            var mockRepo   = new Mock <IVenuesRepository>();
            var mockLogger = new Mock <ILogger <SchedulesController> >();
            var controller = new SchedulesController(mockRepo.Object, mockLogger.Object);

            controller.ModelState.AddModelError("error", "some error");

            // Act
            var result = await controller.PutSchedule(schedule : null);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemple #3
0
        public async Task PutScheduleReturnsNoContentResultTest()
        {
            // Arrange
            int      testId     = 1;
            Schedule schedule   = GetTestSchedules().FirstOrDefault(p => p.Id == testId);
            var      mockLogger = new Mock <ILogger <SchedulesController> >();
            var      mockRepo   = new Mock <IVenuesRepository>();

            mockRepo.Setup(c => c.ChangeState(schedule, schedule, EntityState.Modified)).Verifiable();
            mockRepo.Setup(c => c.SaveChanges()).Returns(Task.CompletedTask);
            mockRepo.Setup(c => c.FirstSchedule(testId)).Returns(schedule);
            var controller = new SchedulesController(mockRepo.Object, mockLogger.Object);

            // Act
            var result = await controller.PutSchedule(schedule);

            // Assert
            Assert.IsType <NoContentResult>(result);
        }