public async Task GivenNoAnonymizationConfiguration_WhenCreatingAnonymizer_CorrectExceptionShouldBeThrow()
        {
            IArtifactProvider client = Substitute.For <IArtifactProvider>();

            client.FetchAsync(Arg.Any <string>(), Arg.Any <Stream>(), Arg.Any <CancellationToken>()).Returns <Task>(
                x =>
            {
                throw new FileNotFoundException();
            });

            ILogger <ExportJobTask> logger = Substitute.For <ILogger <ExportJobTask> >();

            ExportAnonymizerFactory factory = new ExportAnonymizerFactory(client, logger);

            _ = await Assert.ThrowsAsync <AnonymizationConfigurationNotFoundException>(() => factory.CreateAnonymizerAsync("http://dummy", CancellationToken.None));
        }
        public async Task GivenAnInvalidAnonymizationConfiguration_WhenCreatingAnonymizer_CorrectExceptionShouldBeThrow()
        {
            IArtifactProvider client = Substitute.For <IArtifactProvider>();

            client.FetchAsync(Arg.Any <string>(), Arg.Any <Stream>(), Arg.Any <CancellationToken>()).Returns <Task>(
                x =>
            {
                Stream target = x.ArgAt <Stream>(1);
                target.Write(Encoding.UTF8.GetBytes(InvalidConfiguration), 0, SampleConfiguration.Length);
                return(Task.CompletedTask);
            });

            ILogger <ExportJobTask> logger = Substitute.For <ILogger <ExportJobTask> >();

            ExportAnonymizerFactory factory = new ExportAnonymizerFactory(client, logger);

            _ = await Assert.ThrowsAsync <FailedToParseAnonymizationConfigurationException>(() => factory.CreateAnonymizerAsync("http://dummy", CancellationToken.None));
        }
Exemplo n.º 3
0
        private async Task <IAnonymizer> CreateAnonymizerFromConfigContent(string configuration)
        {
            IArtifactProvider client = Substitute.For <IArtifactProvider>();

            client.FetchAsync(Arg.Any <string>(), Arg.Any <Stream>(), Arg.Any <CancellationToken>()).Returns <Task>(
                x =>
            {
                Stream target = x.ArgAt <Stream>(1);
                target.Write(Encoding.UTF8.GetBytes(configuration), 0, configuration.Length);
                return(Task.CompletedTask);
            });

            ILogger <ExportJobTask> logger = Substitute.For <ILogger <ExportJobTask> >();

            ExportAnonymizerFactory factory = new ExportAnonymizerFactory(client, logger);

            return(await factory.CreateAnonymizerAsync("http://dummy", CancellationToken.None));
        }
        public async Task GivenAValidAnonymizationConfiguration_WhenCreatingAnonymizer_AnonymizerShouldBeCreated()
        {
            IArtifactProvider client = Substitute.For <IArtifactProvider>();

            client.FetchAsync(Arg.Any <string>(), Arg.Any <Stream>(), Arg.Any <CancellationToken>()).Returns <Task>(
                x =>
            {
                Stream target = x.ArgAt <Stream>(1);
                target.Write(Encoding.UTF8.GetBytes(SampleConfiguration), 0, SampleConfiguration.Length);
                return(Task.CompletedTask);
            });

            ILogger <ExportJobTask> logger = Substitute.For <ILogger <ExportJobTask> >();

            ExportAnonymizerFactory factory    = new ExportAnonymizerFactory(client, logger);
            IAnonymizer             anonymizer = await factory.CreateAnonymizerAsync("http://dummy", CancellationToken.None);

            Assert.NotNull(anonymizer);
        }