Skip to content

Commit

Permalink
Merge pull request #238 from haevg-rz/BugFixEmtyConfig
Browse files Browse the repository at this point in the history
Bug fix empty config
  • Loading branch information
TobiasMeissner2000 committed Aug 18, 2020
2 parents 8c90346 + 7f74f83 commit 0351b52
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 206 deletions.
9 changes: 4 additions & 5 deletions Tests/TestSamples/Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,21 @@ public static List<TrustCenterMetaInfo> ProvideSampleMetaInfos()
var sample = new List<TrustCenterMetaInfo>()
{
{
new TrustCenterMetaInfo("Sample1", "https://www.speedtestx.de/testfiles/data_1mb.test",
new TrustCenterMetaInfo("Sample1", "https://www.test1Url.de",
new DateTime(2020, 1, 1))
},
{
new TrustCenterMetaInfo("Sample2", "https://www.speedtestx.de/testfiles/data_1mb.test",
new TrustCenterMetaInfo("Sample2", "https://www.test2Url.de",
new DateTime(2020, 1, 1))
},
{
new TrustCenterMetaInfo("Sample3", "https://www.speedtestx.de/testfiles/data_1mb.test",
new TrustCenterMetaInfo("Sample3", "https://www.test3Url.de",
new DateTime(2020, 1, 1))
}
};
return sample;
}

public static Task<byte[]> ProvideSampleTaskByteArray()
{
async Task<byte[]> GetByteArray()
Expand All @@ -138,6 +138,5 @@ async Task<IEnumerable<Certificate>> ProvideSampleOfCertificatesAsync()

return ProvideSampleOfCertificatesAsync();
}

}
}
47 changes: 33 additions & 14 deletions Tests/TrustCenterSearch.Core.Test/ConfigManagerTest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using FluentAssertions;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using TrustCenterSearch.Core;
using TestSamples;
using TrustCenterSearch.Core.DataManagement.Configuration;
using TrustCenterSearch.Core.Models;
using TestSamples;
using Xunit;

namespace TrustCenterSearchCore.Test
namespace TrustCenterSearch.Core.Test
{
public class ConfigManagerTest
{
Expand All @@ -20,15 +21,13 @@ public void AddTrustCenterToConfigTest()

#endregion


#region Act

core.ConfigManager.AddTrustCenterToConfig(new TrustCenterMetaInfo("test123", "test567", DateTime.Now),
config);

#endregion


#region Assert

var result = new Config();
Expand All @@ -49,14 +48,12 @@ public void ConfigIsEmptyTest()

#endregion


#region Act

var result = core.ConfigManager.IsConfigEmpty(config);

#endregion


#region Assert

Assert.True(result);
Expand All @@ -76,14 +73,12 @@ public void ConfigIsNotEmptyTest()

#endregion


#region Act

var result = core.ConfigManager.IsConfigEmpty(config);

#endregion


#region Assert

Assert.False(result);
Expand All @@ -104,19 +99,43 @@ public void DeleteCertificatesOfTrustCenterTest()

#endregion


#region Act

trustCenterManager.DeleteTrustCenterFromConfig(metaDataToDelete, configSample);

#endregion


#region Assert

Assert.DoesNotContain(configSample.TrustCenterMetaInfos,
trustCentermetaInfo => trustCentermetaInfo.Name.Equals(metaDataToDelete.Name));
trustCenterMetaInfo => trustCenterMetaInfo.Name.Equals(metaDataToDelete.Name));

#endregion
}

[Fact(DisplayName = "GetRelativeTrustCenterMetaInfoComplementTest")]
public void GetRelativeTrustCenterMetaInfoComplementTest()
{
#region Arrange

var config = Samples.ProvideSampleConfig();
var newConfig = Samples.ProvideSampleConfig();
newConfig.TrustCenterMetaInfos = Samples.ProvideSampleMetaInfos().TakeLast<TrustCenterMetaInfo>(2).ToList();

var expectedResult = new List<TrustCenterMetaInfo>() { Samples.ProvideSampleMetaInfos()[0] };

#endregion

#region Act

var result = ConfigManager.GetRelativeTrustCenterMetaInfoComplement(config, newConfig);

#endregion

# region Assert

expectedResult.Should().BeEquivalentTo(result);

#endregion
}
}
Expand Down
43 changes: 16 additions & 27 deletions Tests/TrustCenterSearch.Core.Test/CoreTest.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
using Moq;
using System;
using System;
using System.Linq;
using Moq;
using TestSamples;
using TrustCenterSearch.Core;
using TrustCenterSearch.Core.DataManagement.Configuration;
using TrustCenterSearch.Core.DataManagement.TrustCenters;
using TrustCenterSearch.Core.Models;
using Xunit;

namespace TrustCenterSearchCore.Test
namespace TrustCenterSearch.Core.Test
{
public class CoreTest
{
[Fact(DisplayName = "ImportAllCertificatesFromTrustCentersAsyncTest")]
public void ImportAllCertificatesFromTrustCentersAsyncTest()
public async void ImportAllCertificatesFromTrustCentersAsyncTest()
{
#region Arrange

var moqTrustCenterManager = new Mock<TrustCenterManager>();
var moqTrustCenterManager = new Mock<TrustCenterManager> {CallBase = true};
moqTrustCenterManager.Setup(m => m.ImportCertificatesAsync(It.IsAny<TrustCenterMetaInfo>()))
.Returns(Samples.ProvideTaskIEnumerableCertificate);

var core = new Core();
core.TrustCenterManager = moqTrustCenterManager.Object;

core.Config = Samples.ProvideSampleConfig();
var core = new Core
{
TrustCenterManager = moqTrustCenterManager.Object,
Config = Samples.ProvideSampleConfig()
};

#endregion


#region Act

var result = core.ImportAllCertificatesFromTrustCentersAsync();
var result = await core.ImportAllCertificatesFromTrustCentersAsync();

#endregion


#region Assert

Assert.Equal(9, core.Certificates.Count);
Expand All @@ -52,8 +50,7 @@ public void AddTrustCenterAsyncTest()
moqCore.Setup(m => m.IsTrustCenterInputValid(It.IsAny<string>(), It.IsAny<string>()))
.Returns(true);

var moqConfigManager = new Mock<ConfigManager>();
moqConfigManager.CallBase = true;
var moqConfigManager = new Mock<ConfigManager> {CallBase = true};
moqConfigManager.Setup(m => m.SaveConfig(It.IsAny<Config>()))
.Returns(Samples.ProvideSampleConfig);

Expand All @@ -67,18 +64,16 @@ public void AddTrustCenterAsyncTest()
core.ConfigManager = moqConfigManager.Object;
core.TrustCenterManager = moqTrustCenterManager.Object;

core.Config.TrustCenterMetaInfos.RemoveAll(m=>true);
core.Config.TrustCenterMetaInfos.RemoveAll(m => true);

#endregion


#region Act

var result = core.AddTrustCenterAsync("name", "url");

#endregion


#region Assert

var expectedCount = 1;
Expand All @@ -96,14 +91,12 @@ public void DeleteTrustCenterTest()
{
#region Arrange

var moqConfigManager = new Mock<ConfigManager>();
moqConfigManager.CallBase = true;
var moqConfigManager = new Mock<ConfigManager> {CallBase = true};
moqConfigManager.Setup(m => m.SaveConfig(It.IsAny<Config>())).Returns(Samples.ProvideSampleConfig);

var moqTrustCenterManager = new Mock<TrustCenterManager>();
moqTrustCenterManager.CallBase = true;
var moqTrustCenterManager = new Mock<TrustCenterManager> {CallBase = true};
moqTrustCenterManager.Setup(m => m.DeleteTrustCenterFile(It.IsAny<string>())).Returns(null);

var moqCore = new Mock<Core>();
var core = moqCore.Object;

Expand All @@ -115,14 +108,12 @@ public void DeleteTrustCenterTest()

#endregion


#region Act

core.DeleteTrustCenter(Samples.ProvideSampleMetaInfos().FirstOrDefault());

#endregion


#region Assert

var certificateCount = 1;
Expand All @@ -144,15 +135,13 @@ public void IsTrustCenterInputValidTest(string newTrustCenterNameTest, string ne

#endregion


#region Act

var core = new Core();
var exceptionResult = core.AddTrustCenterAsync(newTrustCenterNameTest, newTrustCenterUrlTest);

#endregion


#region Assert

Assert.Equal(errorMessage, exceptionResult.Exception.Message);
Expand Down
11 changes: 3 additions & 8 deletions Tests/TrustCenterSearch.Core.Test/DownloaderTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using TrustCenterSearch.Core.DataManagement.TrustCenters;
using TrustCenterSearch.Core.DataManagement.TrustCenters;
using Xunit;

namespace TrustCenterSearchCore.Test
namespace TrustCenterSearch.Core.Test
{
public class DownloaderTest
{
Expand All @@ -16,20 +15,17 @@ public void IsUrlExistingTest(string url, bool expectedResult)

#endregion


#region Act

var result = Downloader.IsUrlExisting(url);

#endregion


#region Assert

Assert.Equal(result, expectedResult);

#endregion

}

[Theory]
Expand All @@ -55,7 +51,6 @@ public void GetFilePathTest(string name, string dataFolderPath, string expected)
Assert.Equal(result, expected);

#endregion

}
}
}
}
9 changes: 3 additions & 6 deletions Tests/TrustCenterSearch.Core.Test/ImporterTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using TrustCenterSearch.Core.DataManagement.TrustCenters;
using Xunit;

namespace TrustCenterSearchCore.Test
namespace TrustCenterSearch.Core.Test
{
public class ImporterTest
{
[Theory]
[InlineData("", "")]
[InlineData("CO=TEST123", "CO=TEST123")]
[InlineData("CN=Test123, 456","CN=Test123")]
[InlineData("CN=Test123, 456", "CN=Test123")]
[InlineData("CN=123, CN=456, OU=789", "CN=123 CN=456 OU=789")]
[InlineData("CN=123, CN=456, OU=789,123456789", "CN=123 CN=456 OU=789")]
public void GetSubjectElementsToDisplayTest(string input, string expectedResult)
Expand All @@ -17,20 +17,17 @@ public void GetSubjectElementsToDisplayTest(string input, string expectedResult)

#endregion


#region Act

var result = Importer.GetSubjectElementsToDisplay(input);

#endregion


#region Assert

Assert.Equal(expectedResult, result);

#endregion

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
Loading

0 comments on commit 0351b52

Please sign in to comment.