public async Task WithContentAsync_WhenDataIsNonEmptyDomainObjectCollectionContainingNullValues_AssertConvertAsyncWasNotCalledOnDomainObjectToCsvConverter() { IExportDataContentBuilder sut = CreateSut(); await sut.WithContentAsync(CreateExportQuery(), new object[] { null, null, null }); _domainObjectToCsvConverterMock.Verify(m => m.ConvertAsync(It.IsAny <object>()), Times.Never); }
public void WithContentAsync_WhenQueryIsNull_ThrowsArgumentNullException() { using IExportDataContentBuilder sut = CreateSut(); ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.WithContentAsync <IExportQuery, object>(null, _fixture.Create <object>())); Assert.That(result.ParamName, Is.EqualTo("query")); }
public void WithHeaderAsync_WhenQueryIsNull_ThrowsArgumentNullException() { IExportDataContentBuilder sut = CreateSut(); ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.WithHeaderAsync <IExportQuery>(null)); Assert.That(result.ParamName, Is.EqualTo("query")); }
public void WithContentAsync_WhenQueryIsNull_ThrowsArgumentNullException() { IExportDataContentBuilder sut = CreateSut(); ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.WithContentAsync <IExportQuery, IEnumerable <object> >(null, new object[0])); Assert.That(result.ParamName, Is.EqualTo("query")); }
public void WithContentAsync_WhenDataIsNull_ThrowsArgumentNullException() { using IExportDataContentBuilder sut = CreateSut(); ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.WithContentAsync <IExportQuery, object>(CreateExportQuery(), null)); Assert.That(result.ParamName, Is.EqualTo("data")); }
public async Task BuildAsync_WhenNoContentHasBeenWritten_ReturnsNotNull() { using IExportDataContentBuilder sut = CreateSut(); byte[] result = await sut.BuildAsync(); Assert.That(result, Is.Not.Null); }
public async Task BuildAsync_WhenNoContentHasBeenWritten_ReturnsEmptyByteArray() { using IExportDataContentBuilder sut = CreateSut(); byte[] result = await sut.BuildAsync(); Assert.That(result.Length, Is.EqualTo(0)); }
public async Task BuildAsync_WhenNoContentHasBeenWritten_ReturnsByteArray() { using IExportDataContentBuilder sut = CreateSut(); byte[] result = await sut.BuildAsync(); Assert.That(result, Is.TypeOf <byte[]>()); }
public async Task WithHeaderAsync_WhenQueryIsNotNull_AssertGetColumnNamesAsyncWasCalledOnDomainObjectToCsvConverter() { IExportDataContentBuilder sut = CreateSut(); await sut.WithHeaderAsync(CreateExportQuery()); _domainObjectToCsvConverterMock.Verify(m => m.GetColumnNamesAsync(), Times.Once); }
public void WithContentAsync_WhenDataCantBeCastToEnumerableOfDomainObject_ThrowsArgumentException() { IExportDataContentBuilder sut = CreateSut(); ArgumentException result = Assert.ThrowsAsync <ArgumentException>(async() => await sut.WithContentAsync(CreateExportQuery(), _fixture.Create <object>())); Assert.That(result.Message, Is.EqualTo($"Value cannot be cast to IEnumerable<{nameof(Object)}>. (Parameter 'data')")); Assert.That(result.ParamName, Is.EqualTo("data")); }
public async Task WithContentAsync_WhenDataIsNonEmptyDomainObjectCollectionContainingValues_AssertConvertAsyncWasCalledOnDomainObjectToCsvConverter() { IExportDataContentBuilder sut = CreateSut(); object[] domainObjectCollection = _fixture.CreateMany <object>(_random.Next(5, 10)).ToArray(); await sut.WithContentAsync(CreateExportQuery(), domainObjectCollection); _domainObjectToCsvConverterMock.Verify(m => m.ConvertAsync(It.IsNotNull <object>()), Times.Exactly(domainObjectCollection.Length)); }
public MyExportQueryHandler(bool hasExportData, string exportData, IExportDataContentBuilder exportDataContentBuilder) { Core.NullGuard.NotNull(exportData, nameof(exportData)) .NotNull(exportDataContentBuilder, nameof(exportDataContentBuilder)); _hasExportData = hasExportData; _exportData = exportData; _exportDataContentBuilder = exportDataContentBuilder; }
public async Task WithContentAsync_WhenDataIsEmptyDomainObjectCollection_AssertNoWrittenData() { IExportDataContentBuilder sut = CreateSut(); await sut.WithContentAsync(CreateExportQuery(), new object[0]); byte[] result = await sut.BuildAsync(); Assert.That(result.Length, Is.EqualTo(0)); }
public void Dispose_WhenCalled_AssertWriterHasBeenDisposed() { using IExportDataContentBuilder sut = CreateSut(); StreamWriter writer = ((MyExportDataContentBuilder)sut).GetWriter(); sut.Dispose(); Assert.ThrowsAsync <ObjectDisposedException>(async() => await writer.WriteAsync(_fixture.Create <string>())); }
public async Task WithContentAsync_WhenConvertAsyncReturnsNullForOneDomainObject_AssertNoWrittenData() { IExportDataContentBuilder sut = CreateSut(false); await sut.WithContentAsync(CreateExportQuery(), new[] { _fixture.Create <object>() }); byte[] result = await sut.BuildAsync(); Assert.That(result.Length, Is.EqualTo(0)); }
public async Task WithContentAsync_WhenConvertAsyncReturnsEmptyCollectionForOneDomainObject_AssertNoWrittenData() { IExportDataContentBuilder sut = CreateSut(columnValueCollection: new string[0]); await sut.WithContentAsync(CreateExportQuery(), new[] { _fixture.Create <object>() }); byte[] result = await sut.BuildAsync(); Assert.That(result.Length, Is.EqualTo(0)); }
public async Task WithContentAsync_WhenConvertAsyncReturnsNonEmptyCollectionContainingWhiteSpaceValuesForOneDomainObject_AssertColumnValuesHasBeenWritten() { IExportDataContentBuilder sut = CreateSut(columnValueCollection: new[] { " ", " ", " " }); await sut.WithContentAsync(CreateExportQuery(), new[] { _fixture.Create <object>() }); byte[] result = await sut.BuildAsync(); Assert.That(Encoding.UTF8.GetString(result), Is.EqualTo($"\"\";\"\";\"\"{Environment.NewLine}")); }
public async Task BuildAsync_WhenContentHasBeenWritten_ReturnsNonEmptyByteArray() { using IExportDataContentBuilder sut = CreateSut(); await sut.WithContentAsync(CreateExportQuery(), _fixture.Create <string>()); byte[] result = await sut.BuildAsync(); Assert.That(result.Length, Is.GreaterThan(0)); }
public async Task BuildAsync_WhenContentHasBeenWritten_ReturnsNotNull() { using IExportDataContentBuilder sut = CreateSut(); await sut.WithContentAsync(CreateExportQuery(), _fixture.Create <string>()); byte[] result = await sut.BuildAsync(); Assert.That(result, Is.Not.Null); }
public async Task WithHeaderAsync_WhenGetColumnNamesAsyncReturnsNonEmptyCollectionContainingEmptyValues_AssertNoWrittenData() { IExportDataContentBuilder sut = CreateSut(columnNameCollection: new[] { string.Empty, string.Empty, string.Empty }); await sut.WithHeaderAsync(CreateExportQuery()); byte[] result = await sut.BuildAsync(); Assert.That(result.Length, Is.EqualTo(0)); }
public async Task WithHeaderAsync_WhenGetColumnNamesAsyncReturnsNull_AssertNoWrittenData() { IExportDataContentBuilder sut = CreateSut(false); await sut.WithHeaderAsync(CreateExportQuery()); byte[] result = await sut.BuildAsync(); Assert.That(result.Length, Is.EqualTo(0)); }
public async Task WithContentAsync_WhenDataIsNonEmptyDomainObjectCollectionContainingValues_AssertDataForDomainObjectCollectionHasBeenWritten() { IExportDataContentBuilder sut = CreateSut(); object[] domainObjectCollection = _fixture.CreateMany <object>(_random.Next(5, 10)).ToArray(); await sut.WithContentAsync(CreateExportQuery(), domainObjectCollection); byte[] result = await sut.BuildAsync(); Assert.That(new Regex(Environment.NewLine, RegexOptions.Compiled).Matches(Encoding.UTF8.GetString(result)).Count, Is.EqualTo(domainObjectCollection.Length)); }
public async Task BuildAsync_WhenContentHasBeenWritten_ReturnsUTF8ByteArrayForContent() { using IExportDataContentBuilder sut = CreateSut(); string content = _fixture.Create <string>(); await sut.WithContentAsync(CreateExportQuery(), content); byte[] result = await sut.BuildAsync(); Assert.That(Encoding.UTF8.GetString(result), Is.EqualTo(content)); }
public async Task WithHeaderAsync_WhenGetColumnNamesAsyncReturnsNonEmptyCollectionContainingValues_AssertColumnNamesHasBeenWritten() { string[] columnNameCollection = _fixture.CreateMany <string>(_random.Next(5, 10)).ToArray(); IExportDataContentBuilder sut = CreateSut(columnNameCollection: columnNameCollection); await sut.WithHeaderAsync(CreateExportQuery()); byte[] result = await sut.BuildAsync(); Assert.That(Encoding.UTF8.GetString(result), Is.EqualTo(string.Join(';', columnNameCollection.Select(columnName => $"\"{columnName}\"")) + Environment.NewLine)); }
public void Dispose_WhenCalledMultipleTimes_ThrowsNoException() { using IExportDataContentBuilder sut = CreateSut(); int numberOfTimes = _random.Next(5, 10); while (numberOfTimes > 0) { sut.Dispose(); numberOfTimes--; } }
public async Task WithContentAsync_WhenDataIsNonEmptyDomainObjectCollectionContainingValues_AssertConvertAsyncWasCalledOnDomainObjectToCsvConverterForEachDomainObject() { IExportDataContentBuilder sut = CreateSut(); object[] domainObjectCollection = _fixture.CreateMany <object>(_random.Next(5, 10)).ToArray(); await sut.WithContentAsync(CreateExportQuery(), domainObjectCollection); foreach (object domainObject in domainObjectCollection) { _domainObjectToCsvConverterMock.Verify(m => m.ConvertAsync(It.Is <object>(value => value != null && value == domainObject)), Times.Once); } }
public async Task <byte[]> QueryAsync(TExportQuery query) { NullGuard.NotNull(query, nameof(query)); TExportData exportData = await GetExportDataAsync(query); if (exportData == null) { return(new byte[0]); } using IExportDataContentBuilder exportDataContentBuilder = await CreateExportDataContentBuilderAsync(); await exportDataContentBuilder.WithHeaderAsync(query); await exportDataContentBuilder.WithContentAsync(query, exportData); await exportDataContentBuilder.WithFooterAsync(query); return(await exportDataContentBuilder.BuildAsync()); }
public async Task WithContentAsync_WhenQueryAndDataIsNotNull_ThrowsNoException() { using IExportDataContentBuilder sut = CreateSut(); await sut.WithContentAsync(CreateExportQuery(), _fixture.Create <object>()); }
public async Task WithHeaderAsync_WhenQueryIsNotNull_ThrowsNoException() { using IExportDataContentBuilder sut = CreateSut(); await sut.WithHeaderAsync(CreateExportQuery()); }