예제 #1
0
        /// <summary>
        /// Unfolds the configured template for the element.
        /// </summary>
        public override void Execute()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.UnfoldVsTemplateCommand_TraceInitial,
                this.CurrentElement.InstanceName, this.TemplateUri, this.TargetPath, this.TargetFileName, this.SanitizeName, this.SyncName);

            //tracer.TraceData(TraceEventType.Verbose, Resources.UnfoldVsTemplateCommand_StartedEvent, this.CurrentElement);

            var tag = new ReferenceTag
            {
                SyncNames      = this.SyncName,
                TargetFileName = this.TargetFileName
            };

            using (new UnfoldScope(this.CommandAutomation, tag, this.TemplateUri.AbsoluteUri))
            {
                this.GeneratedItem = UnfoldTemplate(this.Solution, this.UriService, this.ServiceProvider, this.CurrentElement,
                                                    new UnfoldVsTemplateSettings
                {
                    TemplateUri    = this.TemplateUri.AbsoluteUri,
                    TargetFileName = this.TargetFileName,
                    TargetPath     = this.TargetPath,
                    SyncName       = this.SyncName,
                    SanitizeName   = this.SanitizeName,
                    Tag            = this.Tag,
                    Id             = this.CommandAutomation.Settings.Id,
                }, false);
            }
        }
        public void AllFieldsFromATag_AreRecognized()
        {
            // Arrange/Act
            var tag = new ReferenceTag(@"<reference
            id = 'power_of_habit'
            title = 'The Power of Habit'
            author = 'Charles Duhigg'
            url = 'http://charlesduhigg.com/the-power-of-habit/'
            date = '2012'
            edition = '1'
            place = 'Warszawa'
            publisher = 'Dom Wydawniczy PWN'
            pages = '123'
            translator = 'Małgorzata Guzowska'
            />");

            // Assert
            Assert.Equal("power_of_habit", tag.Id);
            Assert.Equal("The Power of Habit", tag.Title);
            Assert.Equal("Charles", tag.Author.FirstName);
            Assert.Equal("Duhigg", tag.Author.LastName);
            Assert.Equal("http://charlesduhigg.com/the-power-of-habit/", tag.Url);
            Assert.Equal(1, tag.Edition);
            Assert.Equal("Warszawa", tag.Place);
            Assert.Equal("Dom Wydawniczy PWN", tag.Publisher);
            Assert.Equal("123", tag.Pages);
            Assert.Equal("Małgorzata Guzowska", tag.Translator);
        }
        public void WhenInvalidDateIsProvided_DateIsNull()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference date='2017-13-05' />");

            // Assert
            Assert.False(tag1.Date.HasValue);
        }
        public void WhenPagesArePassed_LeadingAndTraillingWhitespaceIsTrimmed()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference pages='\t123-456 ' />");

            // Assert
            Assert.Equal("123-456", tag1.Pages);
        }
        public void WhenTitleIsPassed_LeadingAndTraillingWhitespaceIsTrimmed()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference title=' Animal Farm\t\n' />");

            // Assert
            Assert.Equal("Animal Farm", tag1.Title);
        }
        public void WhenNoReferenceIdIsProvidedByUser_ItIsAutogenerated()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference />");

            // Assert
            Assert.False(String.IsNullOrWhiteSpace(tag1.Id));
        }
        public void WhenNoDateIsPassed_YearIsNull()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference />");

            // Assert
            Assert.Equal(null, tag1.Year);
        }
        public void AutogeneratedReferenceId_DiffersForDifferentTitles()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='GivenName FamilyName' date='2017' title='abc' />");
            var tag2 = new ReferenceTag("<reference author='GivenName FamilyName' date='2017' title='def' />");

            // Assert
            Assert.NotEqual(tag1.Id, tag2.Id);
        }
예제 #9
0
            public virtual void Initialize()
            {
                var mock = new Mock <IAutomationExtension <IAutomationSettings> >();

                mock.SetupAllProperties();

                this.Automation = mock.Object;
                this.Tag        = new ReferenceTag();
            }
        public void WhenOnlyYearIsProvided_DateIsNull()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference date='2017' />");

            // Assert
            Assert.True(tag1.Year.HasValue);
            Assert.Equal(2017, tag1.Year.Value);
            Assert.False(tag1.Date.HasValue);
        }
예제 #11
0
        internal string RenderReferenceListItemContent(ReferenceTag reference)
        {
            if (reference.Url != null && reference.Date.HasValue && reference.Publisher == null
                ) // heuristics: seems like online content
            {
                return(RenderAsWebsite(reference));
            }

            return(RenderAsBook(reference)); // default
        }
        public void NationalCharactersInAutogeneratedId_AreReplacedWithASCIIEquivalents()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='łódź jeża' date='1968' />");
            var tag2 = new ReferenceTag("<reference author='jeża łódź' date='1968' />");

            // Assert
            Assert.True(tag1.Id.Contains("jeza"));
            Assert.True(tag2.Id.Contains("lodz"));
        }
        public void WhenPublicationYearIsAvailable_ItIsPresentInId()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='Donald Knuth' date='1968' />");
            var tag2 = new ReferenceTag("<reference author='DonaldKnuth' date='1968' />");

            // Assert
            Assert.True(tag1.Id.Contains("1968"));
            Assert.True(tag2.Id.Contains("1968"));
        }
        public void WhenAuthorsNameIsAvailable_ItIsPresentInId()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='Donald Knuth' date='1968' />");
            var tag2 = new ReferenceTag("<reference author='DonaldKnuth' date='1968' />");

            // Assert
            Assert.True(CultureInfo.InvariantCulture.CompareInfo.IndexOf(tag1.Id, "knuth", CompareOptions.IgnoreCase) >= 0);
            Assert.True(CultureInfo.InvariantCulture.CompareInfo.IndexOf(tag2.Id, "donaldknuth", CompareOptions.IgnoreCase) >= 0);
        }
        public void WhenAuthorStringStarthsWithThe_ItIsNotParsedAsName()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='The Economist' date='2010' />");

            // Assert
            Assert.Null(tag1.Author.LastName);
            Assert.Null(tag1.Author.FirstName);
            Assert.Equal("The Economist", tag1.Author.UnprocessedAuthorString);
        }
예제 #16
0
            public virtual void Initialize()
            {
                var mock = new Mock<IAutomationExtension<IAutomationSettings>>();
                mock.SetupAllProperties();

                this.Automation = mock.Object;
                this.Tag = new ReferenceTag();

                this.Scope = CreateScope();
            }
        public void WhenAuthorStringHasThreeWords_ItIsNotParsedAsName()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='Zaufana Trzecia Strona' date='1968' />");

            // Assert
            Assert.Null(tag1.Author.LastName);
            Assert.Null(tag1.Author.FirstName);
            Assert.Equal("Zaufana Trzecia Strona", tag1.Author.UnprocessedAuthorString);
        }
예제 #18
0
        public Tag Parse(TemplateParser parser, TokenCollection tc)
        {
            if (tc.Count > 2 &&
                tc.First.TokenKind == TokenKind.TextData &&
                HasDot(tc))
            {
                ReferenceTag tag = new ReferenceTag();
                Int32        start, end, pos;
                start = end = pos = 0;

                for (Int32 i = 0; i < tc.Count; i++)
                {
                    end = i;
                    switch (tc[i].TokenKind)
                    {
                    case TokenKind.Dot:
                        if (pos == 0)
                        {
                            TokenCollection coll = new TokenCollection();
                            coll.Add(tc, start, end - 1);
                            tag.AddChild(parser.Read(coll));
                            start = i + 1;
                        }
                        break;

                    default:
                        if (tc[i].TokenKind == TokenKind.LeftParentheses)
                        {
                            pos++;
                        }
                        else if (tc[i].TokenKind == TokenKind.RightParentheses)
                        {
                            pos--;
                        }
                        if (i == tc.Count - 1)
                        {
                            TokenCollection coll = new TokenCollection();
                            coll.Add(tc, start, end);
                            tag.AddChild(parser.Read(coll));
                        }
                        break;
                    }
                }
                if (tag.Children.Count > 0)
                {
                    if (tag.Children.Count == 1)
                    {
                        return(tag.Children[0]);
                    }
                }
                return(tag);
            }

            return(null);
        }
        public void WhenDateIsProvided_BothDateAndYearHaveValues()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference date='2017-03-05' />");

            // Assert
            Assert.True(tag1.Year.HasValue);
            Assert.True(tag1.Date.HasValue);
            Assert.Equal(2017, tag1.Year);
            Assert.Equal(new DateTime(2017, 03, 05), tag1.Date);
        }
        public void WhenAuthorStringOnlyContainsOneWord_ItIsNotParsedAsName()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='Johnny' date='2010' />");

            // Assert
            Assert.Null(tag1.Author.LastName);
            Assert.Null(tag1.Author.FirstName);
            Assert.Equal(0, tag1.Author.Initials.Count);
            Assert.Equal("Johnny", tag1.Author.UnprocessedAuthorString);
        }
        public void AutogeneratedReferenceId_DoesntChangeWhenRegenereatingPage()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='Donald Knuth' date='1968' />");
            var tag2 = new ReferenceTag("<reference author='Donald Knuth' date='1968' />");
            var tag3 = new ReferenceTag("<reference author='Donald Knuth' date='1968' />");

            // Assert
            Assert.True(tag1.Id == tag2.Id);
            Assert.True(tag2.Id == tag3.Id);
        }
        public void AutogeneratedReferenceId_DoesntContainIllegalCharacters()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='GivenName FamilyName' date='2017' title=\"FAQ: what's up?\" />");

            Console.WriteLine(tag1.Id);

            // Assert
            Assert.False(tag1.Id.Contains(":"));
            Assert.False(tag1.Id.Contains("?"));
            Assert.False(tag1.Id.Contains("'"));
        }
        public void WhenNoPagesArePassed_PropertyIsNull()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference />");
            var tag2 = new ReferenceTag("<reference pages='' />");
            var tag3 = new ReferenceTag("<reference pages='  ' />");

            // Assert
            Assert.Equal(null, tag1.Pages);
            Assert.Equal(null, tag2.Pages);
            Assert.Equal(null, tag3.Pages);
        }
        public void WhenYearIsPassedAsDate_ItIsProperlyParsed()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference date='2017' />");
            var tag2 = new ReferenceTag("<reference date='1800' />");
            var tag3 = new ReferenceTag("<reference date='2100' />");

            // Assert
            Assert.Equal(2017, tag1.Year);
            Assert.Equal(1800, tag2.Year);
            Assert.Equal(2100, tag3.Year);
        }
        public void AutogeneratedReferenceId_DoesntContainSpaces()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='Pseudonym' date='2017' />");
            var tag2 = new ReferenceTag("<reference author='GivenName FamilyName' date='2017' />");
            var tag3 = new ReferenceTag("<reference author='Zaufana Trzecia Strona' date='2017' />");

            // Assert
            Assert.False(tag1.Id.Contains(" "));
            Assert.False(tag2.Id.Contains(" "));
            Assert.False(tag3.Id.Contains(" "));
        }
        public void AttributeNames_AraNotCaseSensitive()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference title='Animal Farm' />");
            var tag2 = new ReferenceTag("<reference Title='Animal Farm' />");
            var tag3 = new ReferenceTag("<reference TITLE='Animal Farm' />");
            var tag4 = new ReferenceTag("<reference TiTlE='Animal Farm' />");

            // Assert
            Assert.Equal("Animal Farm", tag1.Title);
            Assert.Equal("Animal Farm", tag2.Title);
            Assert.Equal("Animal Farm", tag3.Title);
            Assert.Equal("Animal Farm", tag4.Title);
        }
예제 #27
0
        private void RehydrateModel()
        {
            var patternModel = this.RootElement as PatternModelSchema;

            if (patternModel.IsInTailorMode() && patternModel.Pattern == null)
            {
                var componentModel    = this.GetService <SComponentModel, IComponentModel>();
                var installedToolkits = componentModel.GetService <IEnumerable <IInstalledToolkitInfo> >();

                var toolkitInfo = installedToolkits
                                  .SingleOrDefault(toolkit => toolkit.Id.Equals(patternModel.BaseId, StringComparison.OrdinalIgnoreCase));

                //// TODO: what should be the behavior if we cannot find the base toolkit?
                if (toolkitInfo != null)
                {
                    using (var store = new Store(this.ServiceProvider, typeof(CoreDesignSurfaceDomainModel)))
                    {
                        var baseProductModel = (PatternModelSchema)toolkitInfo.Schema;

                        patternModel.Tailor(baseProductModel, toolkitInfo.Version);

                        // Establish link between hydrdated product line and the runtime product model.
                        var patternManager = this.TryGetService <IPatternManager>();
                        var uriService     = this.TryGetService <IUriReferenceService>();
                        if (patternManager != null && uriService != null)
                        {
                            var fileName     = Path.GetFileName(this.FileName);
                            var productModel = patternManager.Store.FindAll <IProductElement>().FirstOrDefault(element =>
                                                                                                               // Grab the product element that has an artifact reference pointing
                                                                                                               // to this designer file.
                                                                                                               SolutionArtifactLinkReference.GetReferences(element, reference =>
                            {
                                var tag = ReferenceTag.TryDeserialize(reference.Tag);
                                return(tag != null && tag.TargetFileName == fileName);
                            }).Any());

                            // If we got a product model, create a uri pointing to the owning product,
                            // and that becomes the product link.
                            if (productModel != null)
                            {
                                var link = uriService.CreateUri(productModel.Product);
                                patternModel.Pattern.PatternLink = link.ToString();
                            }
                        }

                        this.modelCloned = true;
                    }
                }
            }
        }
예제 #28
0
        private string RenderAsBook(ReferenceTag reference)
        {
            var edition   = RenderEdition(reference.Edition);
            var publisher = RenderPublisher(reference.Publisher, reference.Place);

            var author = (reference.Author.Initials.Count == 0) // author name could not have been parsed using "Name FamilyName" template
                ? reference.Author.UnprocessedAuthorString
                : $@"{reference.Author.LastName}, {reference.Author.Initials[0]}";


            return($@"{author}. ({reference.Year}). <i>{
                    reference.Title
                }</i>.{edition}{publisher}");
        }
        public void TagName_IsNotCaseSensitive()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference title='Animal Farm' />");
            var tag2 = new ReferenceTag("<Reference title='Animal Farm' />");
            var tag3 = new ReferenceTag("<REFERENCE title='Animal Farm' />");
            var tag4 = new ReferenceTag("<ReFeReNcE title='Animal Farm' />");

            // Assert
            Assert.Equal("Animal Farm", tag1.Title);
            Assert.Equal("Animal Farm", tag2.Title);
            Assert.Equal("Animal Farm", tag3.Title);
            Assert.Equal("Animal Farm", tag4.Title);
        }
        public void WhenFormatIs_FirstName_Initial_LastName_FirstNameIsRecognized()
        {
            // Arrange/Act
            var tag1 = new ReferenceTag("<reference author='Philip M. Borden' />");
            var tag2 = new ReferenceTag("<reference author='Carl C. Thompson' />");
            var tag3 = new ReferenceTag("<reference author='Elena T. Bell' />");

            // Assert
            Assert.NotNull(tag1.Author);
            Assert.NotNull(tag2.Author);
            Assert.NotNull(tag3.Author);
            Assert.Equal("Philip", tag1.Author.FirstName);
            Assert.Equal("Carl", tag2.Author.FirstName);
            Assert.Equal("Elena", tag3.Author.FirstName);
        }
예제 #31
0
        private string RenderAsWebsite(ReferenceTag reference)
        {
            Contract.Assert(reference.Date.HasValue);
            Contract.Assert(reference.Url != null);

            var dateTime               = reference.Date.Value;
            var monthAbbreviation      = DateTimeFormatInfo.InvariantInfo.GetAbbreviatedMonthName(dateTime.Month);
            var referenceDateHumanized = $"{dateTime.Day} {monthAbbreviation}. {dateTime.Year}";

            var url = $"<a href='{reference.Url}' target='_blank' rel='nofollow'>{reference.Url}</a>";

            return($@"{reference.Author.UnprocessedAuthorString}, ({reference.Year}). <i>{
                    reference.Title
                }</i>. [online] Available at: {url} [Accessed {referenceDateHumanized}].");
        }
예제 #32
0
            public void Initialize()
            {
                this.settings = Mock.Get(Mock.Of<ITemplateSettings>(s =>
                    s.Owner.Name == "ElementWithTemplateAutomation" &&
                    s.CommandId == CommandId &&
                    s.WizardId == WizardId &&
                    s.TemplateUri == "template://item/CSharp/DataContract" &&
                    s.TargetFileName == Mock.Of<IPropertyBindingSettings>(binding => binding.Value == "MyItem.cs") &&
                    s.TargetPath == Mock.Of<IPropertyBindingSettings>(binding => binding.Value == "")
                ));
                var commandSettings = Mock.Of<IAutomationSettingsSchema>(s =>
                    s.Id == CommandId &&
                    s.Name == "Command" &&
                    s.As<ICommandSettings>() == Mock.Of<ICommandSettings>(c =>
                        c.Id == CommandId &&
                        c.Name == "Command")
                );
                var commandInfo = Mock.Of<IAutomationSettingsInfo>(i =>
                    i.Id == commandSettings.Id &&
                    i.Name == commandSettings.Name &&
                    i.As<IAutomationSettings>() == Mock.Of<IAutomationSettings>(s =>
                        s.Id == commandSettings.Id &&
                        s.Name == commandSettings.Name)
                );
                var wizardSettings = Mock.Of<IAutomationSettingsSchema>(s =>
                    s.Id == WizardId &&
                    s.Name == "Wizard" &&
                    s.As<IWizardSettings>() == Mock.Of<IWizardSettings>(c =>
                        c.Id == WizardId &&
                        c.Name == "Wizard")
                );
                var wizardInfo = Mock.Of<IAutomationSettingsInfo>(i =>
                    i.Id == wizardSettings.Id &&
                    i.Name == wizardSettings.Name &&
                    i.As<IAutomationSettings>() == Mock.Of<IAutomationSettings>(s =>
                        s.Id == wizardSettings.Id &&
                        s.Name == wizardSettings.Name)
                );

                this.settings.Setup(x => x.Owner.AutomationSettings).Returns(new[] { commandSettings, wizardSettings });

                this.command = Mock.Get(Mock.Of<IAutomationExtension>(c => c.Name == "Command"));
                this.wizard = Mock.Get(Mock.Of<IWizardAutomationExtension>(w => w.Name == "Wizard" && w.IsCanceled == false));

                this.owner = Mock.Get(Mock.Of<IProductElement>(o =>
                    o.BeginTransaction() == Mock.Of<ITransaction>() &&
                    o.InstanceName == "ElementWithTemplateAutomation" &&
                    o.Info.AutomationSettings == new[] { commandInfo, wizardInfo } &&
                    o.AutomationExtensions == new[] { this.command.Object, this.wizard.Object }
                ));

                this.owner.DefaultValue = DefaultValue.Mock;

                this.onInstantiated = new Mock<IOnElementInstantiatedEvent>();

                this.automation = new TemplateAutomation(this.owner.Object, this.settings.Object);
                this.automation.OnInstantiated = this.onInstantiated.Object;

                this.solution = new Solution
                {
                    PhysicalPath = Path.GetTempFileName(),
                    Items =
                    {
                        new SolutionFolder 
                        {
                            PhysicalPath = Path.GetTempPath() + "\\Solution Items",
                            Name = "Solution Items"
                        }, 
                        new Project
                        {
                            PhysicalPath = Path.GetTempPath() + "\\MyProject.csproj",
                            Name = "MyProject"
                        }
                    }
                };

                this.automation.Solution = this.solution;
                this.assetUnfoldTemplate = new Mock<ITemplate> { DefaultValue = DefaultValue.Mock };

                this.uriService = Mock.Get(Mock.Of<IUriReferenceService>(s =>
                    s.ResolveUri<ITemplate>(It.IsAny<Uri>()) == this.assetUnfoldTemplate.Object &&
                    s.CreateUri(It.IsAny<IItemContainer>(), null) == new Uri("solution://" + Guid.NewGuid().ToString())
                ));

                this.assetVsTemplate = new Mock<IVsTemplate> { DefaultValue = DefaultValue.Mock };
                this.assetVsTemplate.Setup(x => x.Type).Returns(VsTemplateType.Item);
                this.uriService.Setup(x => x.ResolveUri<IVsTemplate>(It.IsAny<Uri>()))
                    .Returns(this.assetVsTemplate.Object);

                this.automation.UriService = this.uriService.Object;

                this.tag = new ReferenceTag
                {
                    SyncNames = this.settings.Object.SyncName,
                    TargetFileName = this.settings.Object.TargetFileName.Value,
                    Id = this.settings.Object.Id,
                };
            }
예제 #33
0
        /// <summary>
        /// Unfolds the configured template for the element.
        /// </summary>
        public override void Execute()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.UnfoldVsTemplateCommand_TraceInitial,
                this.CurrentElement.InstanceName, this.TemplateUri, this.TargetPath, this.TargetFileName, this.SanitizeName, this.SyncName);

            //tracer.TraceData(TraceEventType.Verbose, Resources.UnfoldVsTemplateCommand_StartedEvent, this.CurrentElement);

            var tag = new ReferenceTag
            {
                SyncNames = this.SyncName,
                TargetFileName = this.TargetFileName
            };

            using (new UnfoldScope(this.CommandAutomation, tag, this.TemplateUri.AbsoluteUri))
            {
                this.GeneratedItem = UnfoldTemplate(this.Solution, this.UriService, this.ServiceProvider, this.CurrentElement,
                    new UnfoldVsTemplateSettings
                    {
                        TemplateUri = this.TemplateUri.AbsoluteUri,
                        TargetFileName = this.TargetFileName,
                        TargetPath = this.TargetPath,
                        SyncName = this.SyncName,
                        SanitizeName = this.SanitizeName,
                        Tag = this.Tag,
                        Id = this.CommandAutomation.Settings.Id,
                    }, false);
            }
        }