private static ReleaseDownloadUrlTestDataPoint CreateTestDataPointFromProperties(String ModName, String ReleaseToken)
        {
            String creationString = $"/download/{ModName}/{ReleaseToken}";

            return(new ReleaseDownloadUrlTestDataPoint
            {
                CreationString = creationString,
                ModName = ModName,
                ReleaseToken = ReleaseToken,
                ObjectFromFor = ReleaseDownloadUrl.For(creationString)
            });
        }
        public void TryAddRelease_WhenNewReleaseDownloadUrlModNameDoesNotMatch_ThrowsInvalidOperationException()
        {
            ReleaseDownloadUrl releaseDownloadUrl = ReleaseDownloadUrl.For($"/download/NotAMatch/1234567890abcd1234567890");

            var exception = Assert.Throws <InvalidOperationException>(() => ModTestData.TestMod.TryAddRelease(new Release(
                                                                                                                  ReleasedAt: ReleaseTestData.TestModGammaReleaseDate,
                                                                                                                  Sha1String: ReleaseTestData.TestModGammaReleaseSha1String,
                                                                                                                  ReleaseDownloadUrl: releaseDownloadUrl,
                                                                                                                  ReleaseFileName: ReleaseFileNameTestData.TestModGammaReleaseFileName,
                                                                                                                  ModVersion: ModVersionTestData.TestModGammaReleaseVersion,
                                                                                                                  FactorioVersion: FactorioVersionTestData.ZeroPointSeventeen,
                                                                                                                  Dependencies: DependencyTestData.TestModGammaReleaseDependencies)));

            Assert.Equal("The specified download URL does not properly reference this mod.", exception.Message);
        }
        public void ModConstructor_WhenReleasesContainsReleasFileNameWithNonMatchingModName_ThrowsArgumentException()
        {
            ReleaseDownloadUrl releaseDownloadUrl = ReleaseDownloadUrl.For($"/download/NotAMatch/{ReleaseDownloadUrlTestData.GenerateValidRandomizedReleaseDownloadUrlToken()}");
            Release            testRelease        = new Release(
                ReleasedAt: ReleaseTestData.TestModAlphaReleaseDate,
                Sha1String: ReleaseTestData.TestModAlphaReleaseSha1String,
                ReleaseDownloadUrl: releaseDownloadUrl,
                ReleaseFileName: ReleaseFileNameTestData.TestModAlphaReleaseFileName,
                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 download URL \"{releaseDownloadUrl}\" 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 static ReleaseDownloadUrl GenerateValidRandomizedReleaseDownloadUrl()
 {
     return(ReleaseDownloadUrl.For(GenerateValidRandomizedReleaseDownloadUrlString()));
 }
예제 #6
0
        public void For_WhenGivenInvalidFormat_ThrowsArgumentException(String releaseDownloadUrlString)
        {
            var exception = Assert.Throws <ArgumentException>(() => ReleaseDownloadUrl.For(releaseDownloadUrlString));

            Assert.Equal($"Unable to parse \"{releaseDownloadUrlString}\" to a valid ReleaseDownloadUrl due to formatting. (Parameter 'releaseDownloadUrlString')", exception.Message);
        }
예제 #7
0
        public void For_WhenGivenEmptyStringOrWhitespace_ThrowsArgumentException(String releaseDownloadUrlString)
        {
            var exception = Assert.Throws <ArgumentException>(() => ReleaseDownloadUrl.For(releaseDownloadUrlString));

            Assert.Equal($"releaseDownloadUrlString may not be empty. (Parameter 'releaseDownloadUrlString')", exception.Message);
        }
예제 #8
0
        public void For_WhenGivenNull_ThrowsArgumentNullException()
        {
            var exception = Assert.Throws <ArgumentNullException>(() => ReleaseDownloadUrl.For(null));

            Assert.Equal("releaseDownloadUrlString is required. (Parameter 'releaseDownloadUrlString')", exception.Message);
        }
예제 #9
0
        public void For_WhenGivenValidString_ReturnsCorrectReleaseToken(String releaseDownloadUrlString, String releaseToken)
        {
            var releaseDownloadUrl = ReleaseDownloadUrl.For(releaseDownloadUrlString);

            Assert.Equal(releaseToken, releaseDownloadUrl.ReleaseToken);
        }
예제 #10
0
        public void For_WhenGivenValidString_ReturnsCorrectModName(String releaseDownloadUrlString, String modName)
        {
            var releaseDownloadUrl = ReleaseDownloadUrl.For(releaseDownloadUrlString);

            Assert.Equal(modName, releaseDownloadUrl.ModName);
        }
예제 #11
0
        public void For_WhenGivenReleaseTokenTooLong_ThrowsArgumentException(String releaseDownloadUrlString)
        {
            var exception = Assert.Throws <ArgumentException>(() => ReleaseDownloadUrl.For(releaseDownloadUrlString));

            Assert.Equal($"The release token specified exceeds the maximum length of {ReleaseDownloadUrl.ReleaseTokenLength}. (Parameter 'releaseDownloadUrlString')", exception.Message);
        }