public override void TestImportSelections() { var testFeed1 = FeedTest.CreateTestFeed(); testFeed1.Uri = FeedTest.Sub1Uri; testFeed1.Name = "Sub 1"; FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub1Uri)).Returns(testFeed1); var testImplementation1 = (Implementation)testFeed1.Elements[0]; var testImplementation2 = new Implementation { ID = "id2", ManifestDigest = new ManifestDigest(sha256: "abc"), Version = new ImplementationVersion("1.0") }; var testFeed2 = new Feed { Uri = FeedTest.Sub2Uri, Name = "Sub 2", Elements = { testImplementation2 } }; FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub2Uri)).Returns(testFeed2); var selections = SelectionsTest.CreateTestSelections(); // Download uncached implementations StoreMock.Setup(x => x.Contains(It.IsAny <ManifestDigest>())).Returns(false); FetcherMock.Setup(x => x.Fetch(new[] { testImplementation1, testImplementation2 })); ExecutorMock.Setup(x => x.Start(It.IsAny <Selections>(), "--arg1", "--arg2")).Returns((Process)null); using (var tempFile = new TemporaryFile("0install-unit-tests")) { selections.SaveXml(tempFile); RunAndAssert(null, 0, selections, tempFile, "--arg1", "--arg2"); } }
public void ProjectMessageCausesExecutorToBeCalledWithExpectedCommandsWhenMessageTypeMismatches() { var commands = new[] { CommandFactory(), CommandFactory() }; var mock = new ExecutorMock(); var handler = new SqlProjectionHandler(typeof(string), _ => commands); var sut = SutFactory(new[] { handler }, mock); var result = sut.Project(new object()); Assert.That(result, Is.EqualTo(0)); Assert.That(mock.Commands, Is.Empty); }
public async void ProjectAsyncMessageCausesExecutorToBeCalledWithExpectedCommandsWhenMessageTypeMatches() { var commands = new[] { CommandFactory(), CommandFactory() }; var mock = new ExecutorMock(); var handler = new SqlProjectionHandler(typeof(object), _ => commands); var sut = SutFactory(new[] { handler }, mock); var result = await sut.ProjectAsync(new object()); Assert.That(result, Is.EqualTo(2)); Assert.That(mock.Commands, Is.EquivalentTo(commands)); }
public async void ProjectAsyncMessagesCausesExecutorToBeCalledWithExpectedCommands( SqlProjectionHandlerResolver resolver, object[] messages, SqlNonQueryCommand[] commands) { var mock = new ExecutorMock(); var sut = SutFactory(resolver, mock); var result = await sut.ProjectAsync(messages); Assert.That(result, Is.EqualTo(commands.Length)); Assert.That(mock.Commands, Is.EquivalentTo(commands)); }
public async Task ProjectAsyncMessageTokenCausesExecutorToBeCalledWithExpectedCommands( SqlProjectionHandlerResolver resolver, object message, SqlNonQueryCommand[] commands) { var mock = new ExecutorMock(); var sut = SutFactory(resolver, mock); var result = await sut.ProjectAsync(message, CancellationToken.None); Assert.That(result, Is.EqualTo(commands.Length)); Assert.That(mock.Commands, Is.EquivalentTo(commands)); }
public void ProjectMessagesCausesExecutorToBeCalledWithExpectedCommands( SqlProjectionHandlerResolver resolver, object[] messages, SqlNonQueryCommand[] commands) { var mock = new ExecutorMock(); var sut = SutFactory(resolver, mock); var result = sut.Project(messages); Assert.That(result, Is.EqualTo(commands.Length)); Assert.That(mock.Commands, Is.EquivalentTo(commands)); }
public void ProjectMessagesCausesExecutorToBeCalledWithExpectedCommandsWhenMessageTypeMismatches() { var commands1 = new[] { CommandFactory(), CommandFactory() }; var commands2 = new[] { CommandFactory(), CommandFactory() }; var mock = new ExecutorMock(); var handler1 = new SqlProjectionHandler(typeof(int), _ => commands1); var handler2 = new SqlProjectionHandler(typeof(bool), _ => commands2); var sut = SutFactory(new[] { handler1, handler2 }, mock); var result = sut.Project(new object[] { 123 }); Assert.That(result, Is.EqualTo(2)); Assert.That(mock.Commands, Is.EquivalentTo(commands1)); }
public async void ProjectAsyncTokenMessagesCausesExecutorToBeCalledWithExpectedCommandsWhenMessageTypeMatches() { var commands1 = new[] { CommandFactory(), CommandFactory() }; var commands2 = new[] { CommandFactory(), CommandFactory() }; var mock = new ExecutorMock(); var handler1 = new SqlProjectionHandler(typeof(int), _ => commands1); var handler2 = new SqlProjectionHandler(typeof(bool), _ => commands2); var sut = SutFactory(new[] { handler1, handler2 }, mock); var result = await sut.ProjectAsync(new object[] { 123, true }, CancellationToken.None); Assert.That(result, Is.EqualTo(4)); Assert.That(mock.Commands, Is.EquivalentTo(commands1.Concat(commands2))); }
public override void TestNormal() { var requirements = RequirementsTest.CreateTestRequirements(); var selections = SelectionsTest.CreateTestSelections(); var testFeed1 = FeedTest.CreateTestFeed(); testFeed1.Uri = FeedTest.Sub1Uri; testFeed1.Name = "Sub 1"; var testImplementation1 = testFeed1[selections.Implementations[0].ID]; FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub1Uri)).Returns(testFeed1); var testImplementation2 = new Implementation { ID = "id2", ManifestDigest = new ManifestDigest(sha256: "abc"), Version = new ImplementationVersion("1.0") }; var testFeed2 = new Feed { Uri = FeedTest.Sub2Uri, Name = "Sub 2", Elements = { testImplementation2 } }; FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub2Uri)).Returns(testFeed2); SolverMock.Setup(x => x.Solve(requirements)).Returns(selections); // Download uncached implementations StoreMock.Setup(x => x.Contains(It.IsAny <ManifestDigest>())).Returns(false); FetcherMock.Setup(x => x.Fetch(new[] { testImplementation1, testImplementation2 })); ExecutorMock.SetupSet(x => x.Main = "Main"); ExecutorMock.SetupSet(x => x.Wrapper = "Wrapper"); ExecutorMock.Setup(x => x.Start(selections, "--arg1", "--arg2")).Returns((Process)null); RunAndAssert(null, 0, selections, "--command=command", "--os=Windows", "--cpu=i586", "--not-before=1.0", "--before=2.0", "--version-for=http://0install.de/feeds/test/test2.xml", "2.0..!3.0", "--main=Main", "--wrapper=Wrapper", "http://0install.de/feeds/test/test1.xml", "--arg1", "--arg2"); }