コード例 #1
0
        public async Task GetWatch_ReturnsWatch()
        {
            // Arrange
            var today    = DateTime.UtcNow;
            var expected = GetSingleWatch(today);

            var mockWatchRepository = new Mock <IWatchRepository>();

            mockWatchRepository.Setup(svc => svc.GetWatchAsync(5)).ReturnsAsync(expected);
            var mockApiConfiguration = new Mock <IApiConfiguration>();
            var controller           = new WatchController(mockWatchRepository.Object, mockApiConfiguration.Object);

            // Act
            var response = await controller.GetWatchAsync(5);

            // Assert
            var actionResult = Assert.IsType <ActionResult <WatchDto> >(response);
            var model        = Assert.IsAssignableFrom <WatchDto>(actionResult.Value);

            Assert.Equal(expected.Id, model.Id);
            Assert.Equal(expected.Model, model.Model);
            Assert.Equal(expected.Title, model.Title);
            Assert.Equal(expected.Gender, model.Gender);
            Assert.Equal(expected.CaseSize, model.CaseSize);
            Assert.Equal(expected.CaseMaterial, model.CaseMaterial);
            Assert.Equal(expected.DateCreated, model.DateCreated);
            Assert.Equal(expected.Brand.Id, model.Brand.Id);
            Assert.Equal(expected.Brand.Title, model.Brand.Title);
            Assert.Equal(expected.Brand.YearFounded, model.Brand.YearFounded);
            Assert.Equal(expected.Brand.Description, model.Brand.Description);
            Assert.Equal(expected.Brand.DateCreated, model.Brand.DateCreated);
            Assert.Equal(expected.MovementId, model.MovementId);
        }
コード例 #2
0
        public async Task GetWatch_ReturnsNotFound_ForInvalidId()
        {
            // Arrange
            var mockWatchRepository = new Mock <IWatchRepository>();

            mockWatchRepository.Setup(svc => svc.GetWatchAsync(55)).ReturnsAsync((Watch)null);
            var mockApiConfiguration = new Mock <IApiConfiguration>();
            var controller           = new WatchController(mockWatchRepository.Object, mockApiConfiguration.Object);

            // Act
            var response = await controller.GetWatchAsync(55);

            // Assert
            var result = Assert.IsType <ActionResult <WatchDto> >(response);
            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(response.Result);

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