Exemplo n.º 1
0
        public async Task Handle_GivenNoKeyIfEncrypted_ShouldFail()
        {
            var useCase  = new CreateProjectUseCase(null, null, null);
            var response = await useCase.Handle(new CreateProjectRequest("Name", KeyStorage.ServerEncrypted, null));

            Assert.Null(response);
            Assert.True(useCase.HasError);
        }
Exemplo n.º 2
0
        public async Task Handle_ServerStorage_ShouldSucceed()
        {
            var mockAsymmetricKeyParametersFactory = new Mock <IAsymmetricKeyParametersFactory>();

            mockAsymmetricKeyParametersFactory.Setup(x => x.Create()).Returns(new AsymmetricKeyParameters("PUBLIC KEY", "PRIVATE KEY"));

            var mockRepository = new Mock <IProjectRepository>();

            mockRepository.Setup(x => x.Add(It.IsAny <Project>())).ReturnsAsync((Project x) => x);

            var useCase  = new CreateProjectUseCase(mockAsymmetricKeyParametersFactory.Object, mockRepository.Object, null);
            var response = await useCase.Handle(new CreateProjectRequest("Name", KeyStorage.Server, null));

            Assert.False(useCase.HasError);

            Assert.Null(response.AsymmetricKey);

            mockRepository.Verify(repo => repo.Add(It.Is <Project>(x => x.Name == "Name" && !x.AsymmetricKey.IsPrivateKeyEncrypted && x.AsymmetricKey.PrivateKey == "PRIVATE KEY" && x.AsymmetricKey.PublicKey == "PUBLIC KEY")), Times.Once);
        }