public void Test_LatestUpdaterIsUsed() { ToolkitDataUnitOfWork unit = new ToolkitDataUnitOfWork(this.Context, this.telemetryContext, new AssemblyStreamVersionReader()); UpdatersController controller = new UpdatersController(unit, new Mock <IFileSaver>().Object, new Mock <IFileRetriever>().Object); var request = new UpdateRequest(telemetryKey: this.TestProgramTelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false, updaterVersion: "1.1" , toolkitVersion: "0.2.0"); UpdateResponse result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.AreEqual(0, result.UpdatePackages.Count); Assert.IsNull(result.Exception); request = new UpdateRequest(telemetryKey: this.TestProgramTelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false, updaterVersion: "1.5" , toolkitVersion: "1.0"); result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.AreEqual(0, result.UpdatePackages.Count); Assert.IsNull(result.Exception); request = new UpdateRequest(telemetryKey: this.TestProgramTelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false, updaterVersion: "1.7" , toolkitVersion: "2.0"); result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.IsNull(result.Exception); Assert.AreEqual(0, result.UpdatePackages.Count); }
public void Test_LatestUpdaterIsNotCompatible_BreakingChanges() { ToolkitDataUnitOfWork unit = new ToolkitDataUnitOfWork(this.Context, this.telemetryContext, versionReader: new AssemblyStreamVersionReader()); UpdatersController controller = new UpdatersController(work: unit, fileSaver: new Mock <IFileSaver>().Object , fileRetriever: new Mock <IFileRetriever>().Object); var request = new UpdateRequest(telemetryKey: this.TestProgramTelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false, updaterVersion: "1.0" , toolkitVersion: "0.2.0"); UpdateResponse result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.AreEqual(expected: 0, actual: result.UpdatePackages.Count); request = new UpdateRequest(telemetryKey: this.TestProgramTelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false, updaterVersion: "1.1.0" , toolkitVersion: "0.9.0"); result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.AreEqual(expected: "1.5.0", actual: result.UpdatePackages.Single().Version); }
public void Test_UpdaterChange() { ToolkitDataUnitOfWork unit = new ToolkitDataUnitOfWork(this.Context, this.telemetryContext, this.assemblyStreamVersionReader); UpdatersController controller = new UpdatersController(unit, new Mock <IFileSaver>().Object, new Mock <IFileRetriever>().Object); var request = new UpdateRequest(telemetryKey: this.ProgramWhichChangesUpdaterTelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false , updaterVersion: "1.0", toolkitVersion: "1.3.0"); UpdateResponse result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.AreEqual("1.6.0", result.UpdatePackages.Single().Version); this.programWhichChangesUpdater.Updater = unit.UpdaterRepository.GetUpdater("UltraNewest").GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); request = new UpdateRequest(telemetryKey: this.ProgramWhichChangesUpdaterTelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false , updaterVersion: "1.0", toolkitVersion: "1.3.0"); result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.AreEqual("9.8.5", result.UpdatePackages.Single().Version); }
private void InsertPrograms(ToolkitDataUnitOfWork unit, WebApp.Core.Models.Portal.Updater updaterOther) { this.testProgram = new Program("Test Program", this.TestProgramTelemetryKey); unit.Programs.Add(this.testProgram); this.programWithDifferentUpdater = new Program("Program with different updater", this.TestProgramWithDifferentUpdaterTelemetryKey); this.programWithDifferentUpdater.Updater = updaterOther; unit.Programs.Add(this.programWithDifferentUpdater); this.programWhichChangesUpdater = new Program("Program which changes updater", this.ProgramWhichChangesUpdaterTelemetryKey); unit.Programs.Add(this.programWhichChangesUpdater); unit.CompleteAsync().GetAwaiter().GetResult(); this.testProgram = this.Context.Programs.First(x => x.Name == this.testProgram.Name); this.programWithDifferentUpdater = this.Context.Programs.First(x => x.Name == this.programWithDifferentUpdater.Name); this.programWhichChangesUpdater = this.Context.Programs.First(x => x.Name == this.programWhichChangesUpdater.Name); }
public void Test_LatestUpdaterIsCompatible() { ToolkitDataUnitOfWork unit = new ToolkitDataUnitOfWork(this.Context, this.telemetryContext, this.assemblyStreamVersionReader); UpdatersController controller = new UpdatersController(unit, new Mock <IFileSaver>().Object, new Mock <IFileRetriever>().Object); var request = new UpdateRequest(telemetryKey: this.TestProgramTelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false, updaterVersion: "1.0" , toolkitVersion: "1.3.0"); UpdateResponse result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.AreEqual("1.6.0", result.UpdatePackages.Single().Version); Assert.AreEqual($"api/v1/updaters/{result.UpdatePackages.Single().PublicId}", result.UpdatePackages.Single().DownloadUrl); request = new UpdateRequest(telemetryKey: this.TestProgramWithDifferentUpdaterTelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false , updaterVersion: "1.0", toolkitVersion: "1.3.0"); result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.AreEqual("1.6.5", result.UpdatePackages.Single().Version); Assert.AreNotEqual(Guid.Empty, result.UpdatePackages[0].PublicId); Assert.AreEqual($"api/v1/updaters/{result.UpdatePackages[0].PublicId}", result.UpdatePackages[0].DownloadUrl); }
public void Test_MissingMinimumToolkitInfo() { ToolkitDataUnitOfWork unit = new ToolkitDataUnitOfWork(this.Context, this.telemetryContext, this.assemblyStreamVersionReader); var defaultUpdater = unit.UpdaterRepository.GetUpdater(DefaultToolkitNames.UpdaterInternalName).GetAwaiter().GetResult(); // assert that empty min version does not break the query unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "", GenerateStream("2.1.8.5"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); UpdatersController controller = new UpdatersController(unit, new Mock <IFileSaver>().Object, new Mock <IFileRetriever>().Object); var request = new UpdateRequest(telemetryKey: this.TestProgram2TelemetryKey, programVersion: new VersionData("0.0", ""), userId: this.User1Guid, acceptBeta: false, updaterVersion: "1.0" , toolkitVersion: "1.3.0"); UpdateResponse result = controller.UpdateCheck(request).GetAwaiter().GetResult(); Assert.AreEqual("2.1.8.5", result.UpdatePackages.Single().Version); Assert.IsNull(result.Exception); }
private IToolkitDataUnitOfWork Prepare() { this.assemblyStreamVersionReader = GetMockVersionReader().Object; ToolkitDataUnitOfWork unit = new ToolkitDataUnitOfWork(this.Context, this.telemetryContext, this.assemblyStreamVersionReader); var defaultUpdater = unit.UpdaterRepository.GetUpdater(DefaultToolkitNames.UpdaterInternalName).GetAwaiter().GetResult(); var user = unit.Users.FirstOrDefault(); var updaterOther = unit.UpdaterRepository.Add("Updater.msi", this.otherUpdaterInternalName, user); var ultraNewest = unit.UpdaterRepository.Add("UltraNewest", "UltraNewest", user); unit.CompleteAsync().GetAwaiter().GetResult(); defaultUpdater = unit.UpdaterRepository.GetUpdater(DefaultToolkitNames.UpdaterInternalName).GetAwaiter().GetResult(); Assert.IsTrue(defaultUpdater.Id > 0); this.InsertPrograms(unit, updaterOther); unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "0.0.0.0", GenerateStream("1.0.0"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); Assert.AreEqual(1, defaultUpdater.Packages.Count); var pkg = unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "0.0.0.0", GenerateStream("1.1.0"), this.saver).GetAwaiter().GetResult(); pkg.IsBeta = true; unit.CompleteAsync().GetAwaiter().GetResult(); Assert.AreEqual(2, defaultUpdater.Packages.Count); unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "0.5.0.0", GenerateStream("1.2.0"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); Assert.AreEqual(3, defaultUpdater.Packages.Count); unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "0.9.0.0", GenerateStream("1.3.0"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "0.9.0.0", GenerateStream("1.4.0"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "0.9.0.0", GenerateStream("1.5.0"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "0.9.0.0", GenerateStream("1.5.0"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "1.3.0.0", GenerateStream("1.6.0"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); unit.UpdaterRepository.StorePackageAsync(updaterOther, "0.0.2.0", GenerateStream("1.6.5"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); pkg = unit.UpdaterRepository.StorePackageAsync(defaultUpdater, "1.3.0.0", GenerateStream("1.7.0"), this.saver).GetAwaiter().GetResult(); pkg.IsBeta = true; unit.CompleteAsync().GetAwaiter().GetResult(); pkg = unit.UpdaterRepository.StorePackageAsync(updaterOther, "0.0.2.0", GenerateStream("1.8.5"), this.saver).GetAwaiter().GetResult(); pkg.IsBeta = true; unit.CompleteAsync().GetAwaiter().GetResult(); unit.UpdaterRepository.StorePackageAsync(ultraNewest, "0.0.0.0", GenerateStream("9.8.5"), this.saver).GetAwaiter().GetResult(); unit.CompleteAsync().GetAwaiter().GetResult(); Assert.IsTrue(defaultUpdater.Packages.Count > 4); return(unit); }