Ejemplo n.º 1
0
        public async Task Handle_ValidatorReturnsFailure_ReturnsFailure(CreateUrl commandFixture, string errorMessageFixture)
        {
            var urlDaoMock = A.Fake <IUrlDao>();

            var createUrlValidatorMock = A.Fake <ICreateUrlValidator>();

            A.CallTo(() => createUrlValidatorMock
                     .Validate(commandFixture))
            .Returns(Result.Fail <CreateUrl>(errorMessageFixture));
            var sut = new CreateUrlHandler(urlDaoMock, createUrlValidatorMock);

            var result = await sut.Handle(commandFixture, CancellationToken.None);

            result.IsFailure.Should().BeTrue();
            result.Error.Should().Be(errorMessageFixture);
        }
Ejemplo n.º 2
0
        public async Task Handle_DaoReturnsFailure_ReturnsFailure(CreateUrl commandFixture, string errorMessageFixture)
        {
            var urlDaoMock = A.Fake <IUrlDao>();

            A.CallTo(() => urlDaoMock
                     .Save(A <Url> .That
                           .Matches(url => url.Path.Equals(commandFixture.Path) &&
                                    url.Id.Equals(commandFixture.Id))))
            .Returns(Task.FromResult(Result.Fail(errorMessageFixture)));
            var createUrlValidatorMock = A.Fake <ICreateUrlValidator>();

            A.CallTo(() => createUrlValidatorMock
                     .Validate(commandFixture))
            .Returns(Result.Ok(commandFixture));
            var sut = new CreateUrlHandler(urlDaoMock, createUrlValidatorMock);

            var result = await sut.Handle(commandFixture, CancellationToken.None);

            result.IsFailure.Should().BeTrue();
            result.Error.Should().Be(errorMessageFixture);
        }
Ejemplo n.º 3
0
        public async Task Handle_DaoReturnsOk_ReturnOk(CreateUrl commandFixture)
        {
            var urlDaoMock = A.Fake <IUrlDao>();

            A.CallTo(() => urlDaoMock
                     .Save(A <Url> .That
                           .Matches(url => url.Path.Equals(commandFixture.Path) &&
                                    url.Id.Equals(commandFixture.Id))))
            .Returns(Task.FromResult(Result.Ok()));
            var createUrlValidatorMock = A.Fake <ICreateUrlValidator>();

            A.CallTo(() => createUrlValidatorMock
                     .Validate(commandFixture))
            .Returns(Result.Ok(commandFixture));

            var sut = new CreateUrlHandler(urlDaoMock, createUrlValidatorMock);

            var result = await sut.Handle(commandFixture, CancellationToken.None);

            result.IsSuccess.Should().BeTrue();
            string expectedValue = commandFixture.Id.ToString("N");

            result.Value.Should().Be(expectedValue);
        }