Ejemplo n.º 1
0
        public async Task CreateClanAsync_ShouldBeOfTypeValidationResult()
        {
            // Arrange
            TestMock.ClanRepository.Setup(repository => repository.IsMemberAsync(It.IsAny <UserId>())).ReturnsAsync(false).Verifiable();

            TestMock.ClanRepository.Setup(repository => repository.ExistsAsync(It.IsAny <string>())).ReturnsAsync(false).Verifiable();

            TestMock.ClanRepository.Setup(repository => repository.Create(It.IsAny <Clan>())).Verifiable();

            TestMock.ClanRepository.Setup(repository => repository.UnitOfWork.CommitAsync(It.IsAny <bool>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            var service = new ClanService(TestMock.ClanRepository.Object);

            // Act
            var result = await service.CreateClanAsync(new UserId(), "test clan");

            // Assert
            result.Should().BeOfType <DomainValidationResult <Clan> >();
            TestMock.ClanRepository.Verify(repository => repository.IsMemberAsync(It.IsAny <UserId>()), Times.Once);
            TestMock.ClanRepository.Verify(repository => repository.ExistsAsync(It.IsAny <string>()), Times.Once);
            TestMock.ClanRepository.Verify(repository => repository.Create(It.IsAny <Clan>()), Times.Once);
            TestMock.ClanRepository.Verify(repository => repository.UnitOfWork.CommitAsync(It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Once);
        }
Ejemplo n.º 2
0
        public async Task CreateClanAsync_WhenMember_ShouldBeOfTypeValidationResultWithErrors()
        {
            // Arrange
            TestMock.ClanRepository.Setup(repository => repository.IsMemberAsync(It.IsAny <UserId>())).ReturnsAsync(true).Verifiable();

            var service = new ClanService(TestMock.ClanRepository.Object);

            // Act
            var result = await service.CreateClanAsync(new UserId(), "test clan");

            // Assert
            result.Should().BeOfType <DomainValidationResult <Clan> >();

            result.Errors.Should().NotBeEmpty();

            TestMock.ClanRepository.Verify(repository => repository.IsMemberAsync(It.IsAny <UserId>()), Times.Once);
        }