コード例 #1
0
        public void ToWebsite_WithCorrectCreateWebsite_ShouldReturnWebsite()
        {
            // Arrange
            Guid websiteId = Guid.NewGuid();

            var createWebsite = new Application.Websites.Commands.UpdateWebsite.UpdateWebsite(websiteId, "mySite", "www.ank.com", new List <string>()
            {
                "cat"
            }, new ImageManipulation("myimg", "png", new byte[4]), "*****@*****.**", "123456");

            // Act
            var website = createWebsite.ToWebsite("encryptedPassword");

            // Assert
            website.Name.Should().Be("mySite");
            website.Url.Should().Be("www.ank.com");
            website.Categories.Count.Should().Be(1);
            website.Categories.First().Value.Should().Be("cat");
            website.Image.Name.Should().Be("myimg");
            website.Image.MimeType.Should().Be("png");
            website.Image.Blob.Length.Should().Be(4);
            website.Email.Should().Be("*****@*****.**");
            website.Password.Should().Be("encryptedPassword");
            website.IsDeleted.Should().Be(false);
        }
コード例 #2
0
        public async Task HandleAsync_WithCorrectCommand_ShouldReturnSuccessResult()
        {
            // Arrange
            Website website = new Website();

            _repositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(website);

            var handler = new UpdateWebsiteHandler(_repositoryMock.Object, _unitOfWorkMock.Object, _cyhperMock.Object);

            // Act
            var command = new Application.Websites.Commands.UpdateWebsite.UpdateWebsite(Guid.Empty, "mySite", "www.mysite.com", new List <string> {
                "cat1", "cat2"
            }, new ImageManipulation("myImage.png", "image/png", new byte[1]), "*****@*****.**", "123456");
            OperationResult <bool> operationResult = await handler.Handle(command, CancellationToken.None);

            // Assert
            _unitOfWorkMock.Verify(x => x.CommitAsync(CancellationToken.None), Times.Once());

            operationResult.Should().BeOfType(typeof(OperationResult <bool>));
            operationResult.IsSuccessful.Should().BeTrue();
        }
コード例 #3
0
        public async Task HandleAsync_WhenWebsiteNotFound_ShouldReturnFailureResult()
        {
            // Arrange
            Website website = null;

            _repositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(website);

            var handler = new UpdateWebsiteHandler(_repositoryMock.Object, _unitOfWorkMock.Object, _cyhperMock.Object);

            // Act
            var command = new Application.Websites.Commands.UpdateWebsite.UpdateWebsite(Guid.Empty, "mySite", "www.mysite.com", new List <string> {
                "cat1", "cat2"
            }, new ImageManipulation("myImage.png", "image/png", new byte[1]), "*****@*****.**", "123456");
            OperationResult <bool> operationResult = await handler.Handle(command, CancellationToken.None);

            // Assert
            operationResult.Should().BeOfType(typeof(OperationResult <bool>));
            operationResult.IsSuccessful.Should().BeFalse();
            operationResult.Errors.First().Key.Should().Be("WebsiteId");
            operationResult.Errors.First().Value.Should().Be(ErrorMessages.WebsiteNotFound);
        }