コード例 #1
0
        public void ImportManager_chains_reader_to_importer() {

            // Arrange
            var dekiApiUri = new XUri("http://mock/@api/deki");
            var importManifest = new XDoc("manifest");
            var item1Uri = dekiApiUri.At("foo", "bar", "abc");
            var item1Doc = new XDoc("item1");
            var item2Uri = dekiApiUri.At("foo", "bar", "def");
            var item2Doc = new XDoc("item2");
            var importResponse = new XDoc("requests")
                .Start("request")
                    .Attr("method", "POST")
                    .Attr("dataid", "abc")
                    .Attr("href", item1Uri)
                    .Start("header").Attr("name", "h_1").Attr("value", "v_1").End()
                    .Start("header").Attr("name", "h_2").Attr("value", "v_2").End()
                .End()
                .Start("request")
                    .Attr("method", "PUT")
                    .Attr("dataid", "def")
                    .Attr("href", item2Uri)
                .End();
            var mock = MockPlug.Register(dekiApiUri);
            mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "import").With("relto", "0")).RequestDocument(importManifest).Response(DreamMessage.Ok(importResponse));
            mock.Expect().Verb("POST").Uri(item1Uri).RequestHeader("h_1", "v_1").RequestHeader("h_2", "v_2").RequestDocument(item1Doc);
            mock.Expect().Verb("PUT").Uri(item2Uri).RequestDocument(item2Doc);

            var mockPackageReader = new Mock<IPackageReader>();
            mockPackageReader.Setup(x => x.ReadManifest(It.IsAny<Result<XDoc>>())).Returns(importManifest.AsResult()).Verifiable("didn't get manifest");
            var item1stream = new MemoryStream(item1Doc.ToBytes());
            mockPackageReader.Setup(x => x.ReadData(It.Is<ImportItem>(y => y.DataId == "abc"), It.IsAny<Result<ImportItem>>()))
                .Returns(() => new ImportItem("abc", importResponse["request[@dataid='abc']"], null, item1stream, item1stream.Length).AsResult())
                .Verifiable();
            var item2stream = new MemoryStream(item2Doc.ToBytes());
            mockPackageReader.Setup(x => x.ReadData(It.Is<ImportItem>(y => y.DataId == "def"), It.IsAny<Result<ImportItem>>()))
                .Returns(() => new ImportItem("def", importResponse["request[@dataid='def']"], null, item2stream, item2stream.Length).AsResult())
                .Verifiable();
            mockPackageReader.Setup(x => x.Dispose()).Verifiable();
            
            // Act
            var manager = ImportManager.CreateAsync(Plug.New(dekiApiUri), 0, mockPackageReader.Object, new Result<ImportManager>()).Wait();
            manager.ImportAsync(new Result()).Wait();

            //Assert
            Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)), mock.VerificationFailure);
            mockPackageReader.VerifyAll();
        }
コード例 #2
0
        public void ImportManager_only_tries_to_read_from_package_when_there_is_a_dataid()
        {
            var dekiApiUri     = new XUri("http://mock/@api/deki");
            var importManifest = new XDoc("manifest");
            var item1Uri       = dekiApiUri.At("foo", "bar", "abc");
            var importResponse = new XDoc("requests")
                                 .Start("request")
                                 .Attr("method", "GET")
                                 .Attr("href", item1Uri)
                                 .End();
            var mock = MockPlug.Register(dekiApiUri);

            mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "import").With("relto", "0")).RequestDocument(importManifest).Response(DreamMessage.Ok(importResponse));
            mock.Expect().Verb("GET").Uri(item1Uri);
            var mockPackageReader = new Mock <IPackageReader>();

            mockPackageReader.Setup(x => x.ReadManifest(It.IsAny <Result <XDoc> >())).Returns(() => importManifest.AsResult());

            // Act
            var manager = ImportManager.CreateAsync(Plug.New(dekiApiUri), 0, mockPackageReader.Object, new Result <ImportManager>()).Wait();

            manager.ImportAsync(new Result()).Wait();

            //Assert
            Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)), mock.VerificationFailure);
            mockPackageReader.Verify(x => x.ReadManifest(It.IsAny <Result <XDoc> >()), Times.Once());
            mockPackageReader.Verify(x => x.ReadData(It.IsAny <ImportItem>(), It.IsAny <Result <ImportItem> >()), Times.Never());
        }
コード例 #3
0
        public void ImportManager_chains_reader_to_importer()
        {
            // Arrange
            var dekiApiUri     = new XUri("http://mock/@api/deki");
            var importManifest = new XDoc("manifest");
            var item1Uri       = dekiApiUri.At("foo", "bar", "abc");
            var item1Doc       = new XDoc("item1");
            var item2Uri       = dekiApiUri.At("foo", "bar", "def");
            var item2Doc       = new XDoc("item2");
            var importResponse = new XDoc("requests")
                                 .Start("request")
                                 .Attr("method", "POST")
                                 .Attr("dataid", "abc")
                                 .Attr("href", item1Uri)
                                 .Start("header").Attr("name", "h_1").Attr("value", "v_1").End()
                                 .Start("header").Attr("name", "h_2").Attr("value", "v_2").End()
                                 .End()
                                 .Start("request")
                                 .Attr("method", "PUT")
                                 .Attr("dataid", "def")
                                 .Attr("href", item2Uri)
                                 .End();
            var mock = MockPlug.Register(dekiApiUri);

            mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "import").With("relto", "0")).RequestDocument(importManifest).Response(DreamMessage.Ok(importResponse));
            mock.Expect().Verb("POST").Uri(item1Uri).RequestHeader("h_1", "v_1").RequestHeader("h_2", "v_2").RequestDocument(item1Doc);
            mock.Expect().Verb("PUT").Uri(item2Uri).RequestDocument(item2Doc);

            var mockPackageReader = new Mock <IPackageReader>();

            mockPackageReader.Setup(x => x.ReadManifest(It.IsAny <Result <XDoc> >())).Returns(importManifest.AsResult()).Verifiable("didn't get manifest");
            var item1stream = new MemoryStream(item1Doc.ToBytes());

            mockPackageReader.Setup(x => x.ReadData(It.Is <ImportItem>(y => y.DataId == "abc"), It.IsAny <Result <ImportItem> >()))
            .Returns(() => new ImportItem("abc", importResponse["request[@dataid='abc']"], null, item1stream, item1stream.Length).AsResult())
            .Verifiable();
            var item2stream = new MemoryStream(item2Doc.ToBytes());

            mockPackageReader.Setup(x => x.ReadData(It.Is <ImportItem>(y => y.DataId == "def"), It.IsAny <Result <ImportItem> >()))
            .Returns(() => new ImportItem("def", importResponse["request[@dataid='def']"], null, item2stream, item2stream.Length).AsResult())
            .Verifiable();
            mockPackageReader.Setup(x => x.Dispose()).Verifiable();

            // Act
            var manager = ImportManager.CreateAsync(Plug.New(dekiApiUri), 0, mockPackageReader.Object, new Result <ImportManager>()).Wait();

            manager.ImportAsync(new Result()).Wait();

            //Assert
            Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)), mock.VerificationFailure);
            mockPackageReader.VerifyAll();
        }
コード例 #4
0
        public void ImportManager_only_tries_to_read_from_package_when_there_is_a_dataid() {
            var dekiApiUri = new XUri("http://mock/@api/deki");
            var importManifest = new XDoc("manifest");
            var item1Uri = dekiApiUri.At("foo", "bar", "abc");
            var importResponse = new XDoc("requests")
                .Start("request")
                    .Attr("method", "GET")
                    .Attr("href", item1Uri)
                .End();
            var mock = MockPlug.Register(dekiApiUri);
            mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "import").With("relto", "0")).RequestDocument(importManifest).Response(DreamMessage.Ok(importResponse));
            mock.Expect().Verb("GET").Uri(item1Uri);
            var mockPackageReader = new Mock<IPackageReader>();
            mockPackageReader.Setup(x => x.ReadManifest(It.IsAny<Result<XDoc>>())).Returns(() => importManifest.AsResult());

            // Act
            var manager = ImportManager.CreateAsync(Plug.New(dekiApiUri), 0, mockPackageReader.Object, new Result<ImportManager>()).Wait();
            manager.ImportAsync(new Result()).Wait();

            //Assert
            Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)), mock.VerificationFailure);
            mockPackageReader.Verify(x => x.ReadManifest(It.IsAny<Result<XDoc>>()), Times.Once());
            mockPackageReader.Verify(x => x.ReadData(It.IsAny<ImportItem>(), It.IsAny<Result<ImportItem>>()), Times.Never());
        }