예제 #1
0
        public async Task UpdateWatch_UpdatesWatch()
        {
            // Arrange
            var watchToPut          = GetWatchToPut();
            var watchUpdated        = GetWatchCreatedOrUpdated();
            var mockWatchRepository = new Mock <IWatchRepository>();

            mockWatchRepository.Setup(svc => svc.UpdateWatchAsync(
                                          It.Is <Watch>(
                                              x => x.Id.Equals(watchToPut.Id) &&
                                              x.Model.Equals(watchToPut.Model) &&
                                              x.Title.Equals(watchToPut.Title) &&
                                              x.Gender.Equals(watchToPut.Gender) &&
                                              x.CaseSize.Equals(watchToPut.CaseSize) &&
                                              x.CaseMaterial.Equals(watchToPut.CaseMaterial) &&
                                              x.BrandId.Equals(watchToPut.BrandId) &&
                                              x.MovementId.Equals(watchToPut.MovementId)))).ReturnsAsync(true);
            var mockApiConfiguration = new Mock <IApiConfiguration>();
            var controller           = new WatchController(mockWatchRepository.Object, mockApiConfiguration.Object);

            // Act
            var response = await controller.UpdateWatchAsync(watchToPut.Id, watchToPut);

            // Assert
            Assert.IsType <NoContentResult>(response);
        }
예제 #2
0
        public async Task UpdateWatch_ThrowsBadRequest_ForMismatchingIds()
        {
            // Arrange
            var watchToPut           = GetWatchToPut();
            var mockWatchRepository  = new Mock <IWatchRepository>();
            var mockApiConfiguration = new Mock <IApiConfiguration>();
            var controller           = new WatchController(mockWatchRepository.Object, mockApiConfiguration.Object);

            // Act
            var ex = await Assert.ThrowsAsync <BadRequestException>(
                () => controller.UpdateWatchAsync(10, watchToPut));

            // Assert
            Assert.Equal("id", ex.Key);
            Assert.Equal("Watch id 15 does not match the id in the route: 10.", ex.Message);
        }
예제 #3
0
        public async Task UpdateWatch_ReturnsNotFound_ForEmptyId()
        {
            // Arrange
            var watchToPut = GetWatchToPut();

            watchToPut.Id = 0;
            var mockWatchRepository  = new Mock <IWatchRepository>();
            var mockApiConfiguration = new Mock <IApiConfiguration>();
            var controller           = new WatchController(mockWatchRepository.Object, mockApiConfiguration.Object);

            // Act
            var ex = await Assert.ThrowsAsync <BadRequestException>(
                () => controller.UpdateWatchAsync(0, watchToPut));

            // Assert
            Assert.Equal("id", ex.Key);
            Assert.Equal("Watch id cannot be 0.", ex.Message);
        }
예제 #4
0
        public async Task UpdateWatch_ReturnsNotFound_ForInvalidId()
        {
            // Arrange
            var watchToPut          = GetWatchToPut();
            var watchUpdated        = GetWatchCreatedOrUpdated();
            var mockWatchRepository = new Mock <IWatchRepository>();

            mockWatchRepository.Setup(svc => svc.UpdateWatchAsync(It.IsAny <Watch>()))
            .ReturnsAsync(false).Verifiable();
            var mockApiConfiguration = new Mock <IApiConfiguration>();
            var controller           = new WatchController(mockWatchRepository.Object, mockApiConfiguration.Object);

            // Act
            var response = await controller.UpdateWatchAsync(watchToPut.Id, watchToPut);

            // Assert
            mockWatchRepository.Verify();
            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(response);

            Assert.Equal("Watch with id 15 cannot be found.", notFoundObjectResult.Value);
        }