public void GetAtomicValues_WhenGivenReleaseFileName_ReturnsCorrectValues(ReleaseFileName releaseFileName, String expectedModName, ModVersion expectedModVersion) { var atomicValues = releaseFileName.GetAtomicValues(); Assert.Equal(expectedModName, atomicValues.ElementAt(0)); Assert.Equal(expectedModVersion, atomicValues.ElementAt(1)); }
private static ReleaseFileNameTestDataPoint CreateTestDataPointFromProperties(String ModName, ModVersion ModVersion) { String creationString = $"{ModName}_{ModVersion}.zip"; return(new ReleaseFileNameTestDataPoint { CreationString = creationString, ModName = ModName, ModVersion = ModVersion, ObjectFromFor = ReleaseFileName.For(creationString) }); }
public void TryAddRelease_WhenNewReleaseFileNameModNameDoesNotMatch_ThrowsInvalidOperationException() { ReleaseFileName releaseFileName = ReleaseFileName.For($"NotAMatch_{ModVersionTestData.TestModGammaReleaseVersion}.zip"); var exception = Assert.Throws <InvalidOperationException>(() => ModTestData.TestMod.TryAddRelease(new Release( ReleasedAt: ReleaseTestData.TestModGammaReleaseDate, Sha1String: ReleaseTestData.TestModGammaReleaseSha1String, ReleaseDownloadUrl: ReleaseDownloadUrlTestData.TestModDownloadUrl, ReleaseFileName: releaseFileName, ModVersion: ModVersionTestData.TestModGammaReleaseVersion, FactorioVersion: FactorioVersionTestData.ZeroPointSeventeen, Dependencies: DependencyTestData.TestModGammaReleaseDependencies))); Assert.Equal("The specified release file name does not properly reference this mod.", exception.Message); }
public void ModConstructor_WhenReleasesContainsReleaseDownloadUrlWithNonMatchingModName_ThrowsArgumentException() { ReleaseFileName releaseFileName = ReleaseFileName.For($"NotAMatch_{ModVersionTestData.TestModAlphaReleaseVersion}.zip"); Release testRelease = new Release( ReleasedAt: ReleaseTestData.TestModAlphaReleaseDate, Sha1String: ReleaseTestData.TestModAlphaReleaseSha1String, ReleaseDownloadUrl: ReleaseDownloadUrlTestData.TestModDownloadUrl, ReleaseFileName: releaseFileName, ModVersion: ModVersionTestData.TestModAlphaReleaseVersion, FactorioVersion: FactorioVersionTestData.ZeroPointSeventeen, Dependencies: DependencyTestData.TestModAlphaReleaseDependencies ); var exception = Assert.Throws <ArgumentException>(() => new Mod( Name: ModTestData.TestModTestDataPoint.Name, Titles: ModTitleTestData.TestModTitles, Releases: new List <Release> { testRelease, ReleaseTestData.TestModBetaRelease })); Assert.Equal($"The mod name in the release filename \"{releaseFileName}\" does not match the specified mod name \"{ModTestData.TestModTestDataPoint.Name}\". (Parameter 'Releases')", exception.Message); }
private static ReleaseTestDataPoint GenerateValidRandomizedTestDataPointWithModName(String modName) { var random = new Random(); List <Dependency> randomizedDependencies = new List <Dependency>(); for (int i = 0; i < random.Next(1, 6); i++) { randomizedDependencies.Add(DependencyTestData.GenerateValidRandomizedDependency()); } String releaseFileNameString = ReleaseFileNameTestData.GenerateValidRandomizedReleaseFileNameStringWithModName(modName); Int32 underscoreIndex = releaseFileNameString.LastIndexOf("_"); String modVersionString = releaseFileNameString.Substring(underscoreIndex + 1, releaseFileNameString.LastIndexOf(".zip") - (underscoreIndex + 1)); return(CreateTestDataPointFromProperties( ReleasedAt: ReleaseTestData.GenerateValidRandomizedReleasedAt(), Sha1String: ReleaseTestData.GenerateValidRandomizedSha1String(), ReleaseDownloadUrl: ReleaseDownloadUrl.For(ReleaseDownloadUrlTestData.GenerateValidRandomizedReleaseDownloadUrlStringWithModName(modName)), ReleaseFileName: ReleaseFileName.For(releaseFileNameString), ModVersion: ModVersion.For(modVersionString), FactorioVersion: FactorioVersionTestData.GenerateValidRandomizedFactorioVersion(), Dependencies: randomizedDependencies )); }
public void NotEqualsOperator_WhenGivenMatchingReleaseFileNames_ReturnsFalse(ReleaseFileName left, ReleaseFileName right) { Assert.False(left != right); }
public void EqualsOperator_WhenGivenMatchingReleaseFileNames_ReturnsTrue(ReleaseFileName left, ReleaseFileName right) { Assert.True(left == right); }
public void GetHashCode_NonMatchingReleaseFileNames_ReturnDifferentHashCode(ReleaseFileName left, ReleaseFileName right) { Assert.NotEqual(left.GetHashCode(), right.GetHashCode()); }
public void GetHashCode_MatchingReleaseFileNames_ReturnSameHashCode(ReleaseFileName left, ReleaseFileName right) { Assert.Equal(left.GetHashCode(), right.GetHashCode()); }
public void ReleaseConstructor_WhenValidParameters_ReturnsCorrectReleasedAt(DateTime releasedAt, String sha1String, ReleaseDownloadUrl releaseDownloadUrl, ReleaseFileName releaseFileName, ModVersion modVersion, FactorioVersion factorioVersion, List <Dependency> dependencies) { var testRelease = new Release(releasedAt, sha1String, releaseDownloadUrl, releaseFileName, modVersion, factorioVersion, dependencies); Assert.Equal(releasedAt, testRelease.ReleasedAt); }
public void For_WhenGivenEmptyStringOrWhitespace_ThrowsArgumentException(String releaseFileNameString) { var exception = Assert.Throws <ArgumentException>(() => ReleaseFileName.For(releaseFileNameString)); Assert.Equal($"releaseFileNameString may not be empty. (Parameter 'releaseFileNameString')", exception.Message); }
public void For_WhenGivenValidString_ReturnsCorrectModVersion(String releaseFileNameString, ModVersion modVersion) { var releaseFileName = ReleaseFileName.For(releaseFileNameString); Assert.Equal(modVersion, releaseFileName.ModVersion); }
public void CopyConstructor_WhenValidParameters_ReturnsCorrectModVersion(ReleaseFileName releaseFileName, ModVersion expectedModVersion) { var testReleaseFileName = new ReleaseFileName(releaseFileName); Assert.Equal(expectedModVersion, testReleaseFileName.ModVersion); }
public void ToString_WhenGivenReleaseFileName_ReturnsCorrectString(ReleaseFileName releaseFileName, String expected) { Assert.Equal(expected, releaseFileName.ToString()); }
private static ReleaseTestDataPoint CreateTestDataPointFromProperties(DateTime ReleasedAt, String Sha1String, ReleaseDownloadUrl ReleaseDownloadUrl, ReleaseFileName ReleaseFileName, ModVersion ModVersion, FactorioVersion FactorioVersion, List <Dependency> Dependencies) { return(new ReleaseTestDataPoint { ReleasedAt = ReleasedAt, Sha1 = Sha1String, ReleaseDownloadUrl = ReleaseDownloadUrl, ReleaseFileName = ReleaseFileName, ModVersion = ModVersion, FactorioVersion = FactorioVersion, Dependencies = Dependencies, ObjectFromConstructor = new Release(ReleasedAt, Sha1String, ReleaseDownloadUrl, ReleaseFileName, ModVersion, FactorioVersion, Dependencies) }); }
public static ReleaseFileName GenerateValidRandomizedReleaseFileName() { return(ReleaseFileName.For(GenerateValidRandomizedReleaseFileNameString())); }
public Release(DateTime ReleasedAt, String Sha1String, ReleaseDownloadUrl ReleaseDownloadUrl, ReleaseFileName ReleaseFileName, ModVersion ModVersion, FactorioVersion FactorioVersion, List <Dependency> Dependencies) { DateTimeValidator.ValidateRequiredDateTimeBeforePresent(ReleasedAt, nameof(ReleasedAt)); ObjectValidator.ValidateRequiredObject(Sha1String, nameof(Sha1String)); ObjectValidator.ValidateRequiredObject(ReleaseDownloadUrl, nameof(ReleaseDownloadUrl)); ObjectValidator.ValidateRequiredObject(ReleaseFileName, nameof(ReleaseFileName)); ObjectValidator.ValidateRequiredObject(ModVersion, nameof(ModVersion)); ObjectValidator.ValidateRequiredObject(FactorioVersion, nameof(FactorioVersion)); ListValidator.ValidateRequiredListNotEmpty(Dependencies, nameof(Dependencies)); Regex sha1CaptureRegex = new Regex(Release.Sha1CapturePattern); Match match = sha1CaptureRegex.Match(Sha1String); if (!match.Success) { throw new ArgumentException($"Unable to parse \"{Sha1String}\" to a valid SHA-1 hash due to formatting.", "Sha1String"); } String sha1 = match.Groups[1].Value; if (sha1.Length != Sha1Length) { throw new ArgumentException($"Unable to parse \"{Sha1String}\" to a valid SHA-1 hash due to length. The SHA-1 hash must have a length of exactly {Release.Sha1Length} characters.", "Sha1String"); } if (ModVersion != ReleaseFileName.ModVersion) { throw new ArgumentException("The specified release file name version does not match the specified release version.", "ReleaseFileName"); } this.ReleasedAt = ReleasedAt; this.ReleaseDownloadUrl = new ReleaseDownloadUrl(ReleaseDownloadUrl); this.ReleaseFileName = new ReleaseFileName(ReleaseFileName); this.Sha1 = sha1; this.ModVersion = new ModVersion(ModVersion); this.FactorioVersion = new FactorioVersion(FactorioVersion); // TODO: We may want to write an .AddDependency() method that validates that the dependency we're adding isn't for the release/mod itself. That would generate a circular dependency. this.Dependencies = Dependencies.ConvertAll(dependency => new Dependency(dependency)); }
public void For_WhenGivenModNameTooLong_ThrowsArgumentException(String releaseFileNameString) { var exception = Assert.Throws <ArgumentException>(() => ReleaseFileName.For(releaseFileNameString)); Assert.Equal($"The mod name specified exceeds the maximum length of {Mod.NameLength}. (Parameter 'releaseFileNameString')", exception.Message); }
public void ToStringOperator_WhenGivenReleaseFileName_ReturnsCorrectString(ReleaseFileName releaseFileName, String expected) { String releaseFileNameString = releaseFileName; Assert.Equal(expected, releaseFileNameString); }
public void For_WhenGivenValidString_ReturnsCorrectModName(String releaseFileNameString, String modName) { var releaseFileName = ReleaseFileName.For(releaseFileNameString); Assert.Equal(modName, releaseFileName.ModName); }
public void ToReleaseFileNameOperator_WhenGivenString_ReturnsCorrectReleaseFileName(ReleaseFileName releaseFileName, String releaseFileNameString) { ReleaseFileName newReleaseFileName = (ReleaseFileName)releaseFileNameString; Assert.Equal(releaseFileName, newReleaseFileName); }
public void For_WhenGivenNull_ThrowsArgumentNullException() { var exception = Assert.Throws <ArgumentNullException>(() => ReleaseFileName.For(null)); Assert.Equal("releaseFileNameString is required. (Parameter 'releaseFileNameString')", exception.Message); }
public void Equals_WhenProvidedNotEqualReleaseFileNames_ReturnsFalse(ReleaseFileName left, ReleaseFileName right) { Assert.False(left.Equals((Object)right)); }
public void For_WhenGivenInvalidFormat_ThrowsArgumentException(String releaseFileNameString) { var exception = Assert.Throws <ArgumentException>(() => ReleaseFileName.For(releaseFileNameString)); Assert.Equal($"Unable to parse \"{releaseFileNameString}\" to a valid ReleaseFileName due to formatting. (Parameter 'releaseFileNameString')", exception.Message); }
public void CopyConstructor_WhenValidParameters_ReturnsCorrectReleaseFileName(Release release, ReleaseFileName expectedReleaseFileName) { var testRelease = new Release(release); Assert.Equal(expectedReleaseFileName, testRelease.ReleaseFileName); }