コード例 #1
0
        private void SetupRoutePart(PackagePart packagePartToMapTo) {
            var contentItem = new ContentItem { ContentType = "Package" };
            var routePart = new AutoroutePart {Record = new AutoroutePartRecord()};
            contentItem.Weld(routePart);
            contentItem.Weld(packagePartToMapTo);

        }
コード例 #2
0
        public void ContentItemPropertyOnPartRootsYou() {
            var contentItem = new ContentItem();
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("TestingPart"), new SettingsDictionary()) };
            var anotherPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("AnotherPart"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);
            contentItem.Weld(anotherPart);

            dynamic contentItemDynamic = contentItem;
            dynamic testingPartDynamic  = contentItemDynamic.TestingPart;
            dynamic anotherPartDynamic  = contentItemDynamic.AnotherPart;

            dynamic contentItemDynamic1  = testingPartDynamic.ContentItem;
            dynamic contentItemDynamic2  = anotherPartDynamic.ContentItem;

            Assert.That((object)contentItemDynamic1, Is.SameAs(contentItem));
            Assert.That((object)contentItemDynamic2, Is.SameAs(contentItem));
        }
コード例 #3
0
        public void ContentPartsAlsoProjectPartNamesAsProperties() {
            var contentItem = new ContentItem();
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("TestingPart"), new SettingsDictionary()) };
            var anotherPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("AnotherPart"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);
            contentItem.Weld(anotherPart);

            dynamic contentItemDynamic = contentItem;
            dynamic testingPartDynamic  = contentItemDynamic.TestingPart;
            dynamic anotherPartDynamic  = contentItemDynamic.AnotherPart;
            dynamic testingPartDynamic2  = testingPartDynamic.TestingPart;
            dynamic anotherPartDynamic2  = testingPartDynamic.AnotherPart;

            Assert.That((object)testingPartDynamic, Is.SameAs(testingPart));
            Assert.That((object)anotherPartDynamic, Is.SameAs(anotherPart));
            Assert.That((object)testingPartDynamic2, Is.SameAs(testingPart));
            Assert.That((object)anotherPartDynamic2, Is.SameAs(anotherPart));
        }
コード例 #4
0
ファイル: ContentItemTests.cs プロジェクト: zhongzf/Brochard
        public void ContentShouldOnlyContainParts()
        {
            var contentItem = new ContentItem();
            contentItem.Weld<MyPart>();
            contentItem.Alter<MyPart>(x => x.Text = "test");

            var json = JsonConvert.SerializeObject(contentItem);

            Assert.Contains(@"""MyPart"":{""Text"":""test""}", json);
        }
コード例 #5
0
        public void ActualPropertiesTakePriority() {
            var contentItem = new ContentItem();
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("Parts"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);

            dynamic contentItemDynamic = contentItem;
            dynamic testingPartDynamic  = contentItemDynamic.Parts;


            Assert.That((object)testingPartDynamic, Is.AssignableTo<IEnumerable<ContentPart>>());
        }
 private ContentPart CreateContentItemPart() {
     var partDefinition = FooPartDefinition();
     var typeDefinition = new ContentTypeDefinitionBuilder()
         .WithPart(partDefinition, part => { })
         .Build();
     var contentItem = new ContentItem {
         VersionRecord = new ContentItemVersionRecord {
             ContentItemRecord = new ContentItemRecord()
         }
     };
     var contentPart = new ContentPart {
         TypePartDefinition = typeDefinition.Parts.Single()
     };
     contentItem.Weld(contentPart);
     contentItem.Weld(new InfosetPart {
         Infoset = contentItem.Record.Infoset,
         VersionInfoset = contentItem.VersionRecord.Infoset
     });
     return contentPart;
 }
コード例 #7
0
        public void ShouldCallRecommendedVersionUpdater() {
            PackagePart newPackagePart = new PackagePart { Record = new PackagePartRecord(), PackageID = "foo", PackageVersion = "1.0" };
            var contentItem = new ContentItem { ContentType = "Package" };
            contentItem.Weld(newPackagePart);
            PublishedPackage publishedPackage = new PublishedPackage { Id = newPackagePart.PackageID, Version = newPackagePart.PackageVersion };
            _mockedOdataContext.SetupGet(oc => oc.Packages).Returns(new[] { publishedPackage }.AsQueryable());
            _mockedContentManager.Setup(cm => cm.New(It.IsAny<string>())).Returns(contentItem);

            _creator.CreateNewPackagePart(new PackageLogEntry { PackageId = newPackagePart.PackageID, PackageVersion = newPackagePart.PackageVersion});

            _mockedRecommendedVersionUpdater.Verify(rvu => rvu.SetRecommendedVersionFlagsOfOtherPackagesWithSameId(newPackagePart));
        }
コード例 #8
0
        public override async Task<IDisplayResult> UpdateAsync(ContentItem model, IUpdateModel updater)
        {
            var viewModel = new EditContainedPartViewModel();

            if (await updater.TryUpdateModelAsync(viewModel, "ListPart"))
            {
                model.Weld<ContainedPart>();
                model.Alter<ContainedPart>(x => x.ListContentItemId = viewModel.ContainerId);
            }

            return await base.UpdateAsync(model, updater);
        }
コード例 #9
0
        public void ShouldCreateNewPackagePartWhenNoExistingOrchardVersionsOfPackageExist() {
            PackagePart newPackagePart = new PackagePart { Record = new PackagePartRecord(), PackageID = "foo", PackageVersion = "1.0" };
            var contentItem = new ContentItem { ContentType = "Package" };
            contentItem.Weld(newPackagePart);
            PublishedPackage publishedPackage = new PublishedPackage { Id = newPackagePart.PackageID, Version = newPackagePart.PackageVersion };
            _mockedOdataContext.SetupGet(oc => oc.Packages).Returns(new[] { publishedPackage }.AsQueryable());
            _mockedContentManager.Setup(cm => cm.New(It.IsAny<string>())).Returns(contentItem);
            _mockedPackageService.Setup(ps => ps.PackageExists(newPackagePart.PackageID, newPackagePart.PackageVersion, It.IsAny<VersionOptions>())).Returns(false);

            _creator.CreateNewPackagePart(new PackageLogEntry { PackageId = newPackagePart.PackageID, PackageVersion = newPackagePart.PackageVersion });

            _mockedContentManager.Verify(cm => cm.Create(It.IsAny<ContentItem>(), It.IsAny<VersionOptions>()), Times.Once());
        }
コード例 #10
0
ファイル: ContentItemTests.cs プロジェクト: zhongzf/Brochard
        public void ShouldAlterPart()
        {
            var contentItem = new ContentItem();
            contentItem.Weld<MyPart>();
            contentItem.Alter<MyPart>(x => x.Text = "test");

            var json = JsonConvert.SerializeObject(contentItem);

            var contentItem2 = JsonConvert.DeserializeObject<ContentItem>(json);

            Assert.NotNull(contentItem.Content.MyPart);
            Assert.Equal("test", (string)contentItem.Content.MyPart.Text);
        }
コード例 #11
0
ファイル: ContentItemTests.cs プロジェクト: zhongzf/Brochard
        public void ShouldSerializeParts()
        {
            var contentItem = new ContentItem();
            var myPart = new MyPart { Text = "test" };
            contentItem.Weld(myPart);

            var json = JsonConvert.SerializeObject(contentItem);

            var contentItem2 = JsonConvert.DeserializeObject<ContentItem>(json);

            Assert.NotNull(contentItem.Content.MyPart);
            Assert.Equal("test", (string)contentItem.Content.MyPart.Text);
        }
コード例 #12
0
ファイル: ContentItemTests.cs プロジェクト: zhongzf/Brochard
        public void ContentShouldStoreFields()
        {
            var contentItem = new ContentItem();
            contentItem.Weld<MyPart>();
            contentItem.Alter<MyPart>(x => x.Text = "test");
            contentItem.Alter<MyPart>(x =>
            {
                x.Weld<MyField>("myField");
                x.Alter<MyField>("myField", f => f.Value = 123);
            });

            var json = JsonConvert.SerializeObject(contentItem);

            Assert.Contains(@"""MyPart"":{""Text"":""test"",""myField"":{""Value"":123}}", json);
        }
コード例 #13
0
        public override async Task<IDisplayResult> UpdateAsync(ContentItem contentItem, IUpdateModel updater)
        {
            var testContentPart = contentItem.As<TestContentPartA>();

            if (testContentPart == null)
            {
                return null;
            }

            if (await updater.TryUpdateModelAsync(testContentPart, ""))
            {
                if (testContentPart.Line.EndsWith(" "))
                {
                    updater.ModelState.AddModelError(nameof(testContentPart.Line), "Value cannot end with a space");
                }
                else
                {
                    contentItem.Weld(testContentPart);
                }
            }
            
            return Shape("TestContentPartA_Edit", testContentPart).Location("Content");
        }
コード例 #14
0
        public void ShouldLogMessageWhenPackagePartAlreadyExists()
        {
            PackagePart newPackagePart = new PackagePart { Record = new PackagePartRecord(), PackageID = "foo", PackageVersion = "1.0" };
            var contentItem = new ContentItem { ContentType = "Package" };
            contentItem.Weld(newPackagePart);

            PublishedPackage publishedPackage = new PublishedPackage { Id = newPackagePart.PackageID, Version = newPackagePart.PackageVersion };

            _mockedOdataContext.SetupGet(oc => oc.Packages).Returns(new[] { publishedPackage }.AsQueryable());
            _mockedContentManager.Setup(cm => cm.New(It.IsAny<string>())).Returns(contentItem);
            _mockedPackageService.Setup(ps => ps.PackageExists(newPackagePart.PackageID, newPackagePart.PackageVersion, It.IsAny<VersionOptions>()))
                .Returns(true);

            _creator.CreateNewPackagePart(new PackageLogEntry { PackageId = newPackagePart.PackageID, PackageVersion = newPackagePart.PackageVersion });

            _mockedLogger.Verify(l => l.Log(LogLevel.Information, null, It.Is<string>(s => s.Contains("already exists in the gallery")),
                It.IsAny<object[]>()), Times.Once());
        }
コード例 #15
0
        public void DumpContentItem_DepthSix() {
            var contentItem = new ContentItem { ContentType = "TestContentType" };
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("TestingPart"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);

            var objectDumper = new ObjectDumper(6);
            var xElement = objectDumper.Dump(contentItem, "Model");

            var stringBuilder = new StringBuilder();
            ObjectDumper.ConvertToJSon(xElement, stringBuilder);
            var json = stringBuilder.ToString();

            var jObject = new JObject(
                new JProperty("name", "Model"),
                new JProperty("value", "ContentItem"),
                new JProperty("children", new JArray(
                    new JObject(
                        new JProperty("name", "Id"),
                        new JProperty("value", "0")),
                    new JObject(
                        new JProperty("name", "Version"),
                        new JProperty("value", "0")),
                    new JObject(
                        new JProperty("name", "ContentType"),
                        new JProperty("value", "&quot;TestContentType&quot;")),
                    new JObject(
                        new JProperty("name", "TestingPart"),
                        new JProperty("value", "ContentPart"),
                        new JProperty("children", new JArray(
                            new JObject(
                                new JProperty("name", "Id"),
                                new JProperty("value", "0")),
                            new JObject(
                                new JProperty("name", "TypeDefinition"),
                                new JProperty("value", "null")),
                            new JObject(
                                new JProperty("name", "TypePartDefinition"),
                                new JProperty("value", "ContentTypePartDefinition"),
                                new JProperty("children", new JArray(
                                    new JObject(
                                        new JProperty("name", "PartDefinition"),
                                        new JProperty("value", "ContentPartDefinition"),
                                        new JProperty("children", new JArray(
                                                new JObject(
                                                    new JProperty("name", "Name"),
                                                    new JProperty("value", "&quot;TestingPart&quot;")),
                                                new JObject(
                                                    new JProperty("name", "Fields"),
                                                    new JProperty("value", "ContentPartFieldDefinition[]")),
                                                new JObject(
                                                    new JProperty("name", "Settings"),
                                                    new JProperty("value", "SettingsDictionary"))))),
                                    new JObject(
                                        new JProperty("name", "Settings"),
                                        new JProperty("value", "SettingsDictionary")),
                                    new JObject(
                                        new JProperty("name", "ContentTypeDefinition"),
                                        new JProperty("value", "null"))))),
                            new JObject(
                                new JProperty("name", "PartDefinition"),
                                new JProperty("value", "ContentPartDefinition"),
                                new JProperty("children", new JArray(
                                    new JObject(
                                        new JProperty("name", "Name"),
                                        new JProperty("value", "&quot;TestingPart&quot;")),
                                    new JObject(
                                        new JProperty("name", "Fields"),
                                        new JProperty("value", "ContentPartFieldDefinition[]")),
                                    new JObject(
                                        new JProperty("name", "Settings"),
                                        new JProperty("value", "SettingsDictionary"))))),
                            new JObject(
                                new JProperty("name", "Settings"),
                                new JProperty("value", "SettingsDictionary")),
                            new JObject(
                                new JProperty("name", "Fields"),
                                new JProperty("value", "List&lt;ContentField&gt;"))))))));

            ComparareJsonObject(jObject, json);
        }
コード例 #16
0
        public void NullCheckingCanBeDoneOnProperties() {
            var contentItem = new ContentItem();
            var contentPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("FooPart"), new SettingsDictionary()) };
            var contentField = new ContentField { PartFieldDefinition = new ContentPartFieldDefinition(new ContentFieldDefinition("FooType"), "FooField", new SettingsDictionary()) };

            dynamic item = contentItem;
            dynamic part = contentPart;

            Assert.That(item.FooPart == null, Is.True);
            Assert.That(item.FooPart != null, Is.False);

            contentItem.Weld(contentPart);

            Assert.That(item.FooPart == null, Is.False);
            Assert.That(item.FooPart != null, Is.True);
            Assert.That(item.FooPart, Is.SameAs(contentPart));

            Assert.That(part.FooField == null, Is.True);
            Assert.That(part.FooField != null, Is.False);
            Assert.That(item.FooPart.FooField == null, Is.True);
            Assert.That(item.FooPart.FooField != null, Is.False);

            contentPart.Weld(contentField);

            Assert.That(part.FooField == null, Is.False);
            Assert.That(part.FooField != null, Is.True);
            Assert.That(item.FooPart.FooField == null, Is.False);
            Assert.That(item.FooPart.FooField != null, Is.True);
            Assert.That(part.FooField, Is.SameAs(contentField));
            Assert.That(item.FooPart.FooField, Is.SameAs(contentField));
        }
コード例 #17
0
        public void ShouldLogMessageWhenPackageIsCreated()
        {
            PackagePart newPackagePart = new PackagePart { Record = new PackagePartRecord(), PackageID = "foo", PackageVersion = "1.0" };
            var contentItem = new ContentItem { ContentType = "Package" };
            contentItem.Weld(newPackagePart);
            PublishedPackage publishedPackage = new PublishedPackage { Id = newPackagePart.PackageID, Version = newPackagePart.PackageVersion };

            _mockedOdataContext.SetupGet(oc => oc.Packages).Returns(new[] { publishedPackage }.AsQueryable());
            _mockedContentManager.Setup(cm => cm.New(It.IsAny<string>())).Returns(contentItem);

            _creator.CreateNewPackagePart(new PackageLogEntry { PackageId = newPackagePart.PackageID, PackageVersion = newPackagePart.PackageVersion });

            _mockedLogger.Verify(l => l.Log(LogLevel.Information, null, It.Is<string>(s => s.StartsWith("Created PackagePart")),
                It.IsAny<object[]>()), Times.Once());
        }
コード例 #18
0
 /// <summary>
 /// Adds a content part by its type.
 /// </summary>
 /// <typeparam name="part">The part to add to the <see cref="ContentItem"/>.</typeparam>
 /// <returns>The current <see cref="ContentItem"/> instance.</returns>
 public static ContentItem Weld <TPart>(this ContentItem contentItem, TPart part) where TPart : ContentPart
 {
     contentItem.Weld(typeof(TPart).Name, part);
     return(contentItem);
 }
コード例 #19
0
ファイル: PaypalTests.cs プロジェクト: richinoz/Orchard1.6
        public void Create_Returns_ViewResult_On_Success()
        {
            var server = new Mock<HttpServerUtilityBase>(MockBehavior.Loose);
            var response = new Mock<HttpResponseBase>(MockBehavior.Strict);

            var request = new Mock<HttpRequestBase>(MockBehavior.Loose);
            request.Setup(x => x.ApplicationPath).Returns("/");
            request.Setup(x => x.Url).Returns(new Uri("http://localhost"));
            request.Setup(x => x.BinaryRead(It.IsAny<int>())).Returns(new byte[] { });
        
            request.SetupGet(r => r["txn_id"]).Returns("Tx101");
            request.SetupGet(r => r["custom"]).Returns("1");
            request.SetupGet(r => r["mc_gross"]).Returns("1");
            request.SetupGet(r => r.ContentLength).Returns(1);

            var context = new Mock<HttpContextBase>();
            context.SetupGet(x => x.Request).Returns(request.Object);
            context.SetupGet(x => x.Response).Returns(response.Object);
            context.SetupGet(x => x.Server).Returns(server.Object);

            var yourMockedResponseStream = new MemoryStream();

            var sw = new StreamWriter(yourMockedResponseStream);            
            sw.Write("VERIFIED");
            sw.Flush();
            yourMockedResponseStream.Position = 0;

            var streamReader = new MemoryStream();

            var webResponse = new Mock<WebResponse>();
            webResponse.Setup(c => c.GetResponseStream()).Returns(yourMockedResponseStream);

            var webRequest = new Mock<WebRequest>();
            webRequest.Setup(c => c.GetResponse()).Returns(webResponse.Object);
            webRequest.Setup(c => c.GetRequestStream()).Returns(streamReader);

            var factory = new Mock<IWebRequestFactory>();
            factory.Setup(c => c.Create(It.IsAny<string>())).Returns(webRequest.Object);

            
            var orderService = _container.Resolve<IOrderService>();
            var serialisationUtils = _container.Resolve<ISerialisation>();

            var orderPart = new Mock<OrderPart>();
            orderPart.Setup(x => x.Amount).Returns(1);
            orderPart.Setup(x => x.Details).Returns(serialisationUtils.SerializeToXml(new Order()));
            orderPart.Setup(x => x.TransactionId).Returns("testTXN");   

            var contentItem =new ContentItem();            
            contentItem.Weld(orderPart.Object);

            _orderPartServiceMock.Setup(x => x.Get(It.IsAny<int>())).Returns(contentItem);
            var controller = new PaypalController(orderService, factory.Object, _container.Resolve<IClock>());
            
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);
            
            //act
            var results = controller.IPN();

            //assert
            Assert.IsNotNull(results);
            Assert.IsInstanceOf(typeof(ViewResult), results);

            orderPart.VerifySet(x => x.TransactionId = "Tx101");
        }