private void ExecuteStep(Dictionary <string, object> inputParameters, int stage, string message, string primaryentityname, string logicalName, Guid id, bool isAsync, Action finalize, Action onDone)
        {
            var methods = this.pluginMethodCache.ForPlugin(this.plugin.GetType(), stage, message, logicalName, isAsync, false);

            if (methods.Length > 0)
            {
                if (inputParameters != null && inputParameters.Count > 0)
                {
                    var pluginExecutionContext = new Services.PluginExecutionContext(stage, 1, message, primaryentityname, id, isAsync);
                    foreach (var key in inputParameters.Keys)
                    {
                        pluginExecutionContext.InputParameters.Add(key, inputParameters[key]);
                    }

                    var serviceProvider = new Services.ServiceProvider(pluginExecutionContext, this, this.plugin.GetType().Assembly);
                    this.plugin.Execute(serviceProvider);
                    finalize?.Invoke();
                    onDone?.Invoke();
                }
            }
            else
            {
                if (onDone != null)
                {
                    throw new Exceptions.UnexpectedEventListenerException(plugin.GetType(), message, stage);
                }
                else
                {
                    finalize?.Invoke();
                }
            }
        }
Beispiel #2
0
        public void DefaultPage_TestPageInitialState()
        {
            var personRepo   = new Mock <IPersonRepository>();
            var yearProvider = new Mock <IYearProvider>();

            var collection = new ServiceCollection();

            collection.AddScoped((sp) => { return(personRepo.Object); });
            collection.AddScoped((sp) => { return(yearProvider.Object); });

            var provider = new Services.ServiceProvider(collection.BuildServiceProvider());


            WebApplicationProxy.Create(typeof(_Default), provider);

            var page = WebApplicationProxy.GetPageByLocation <_Default>("/default.aspx", collection);

            page.RunToEvent(WebFormEvent.PreRender);

            var employeeData = page.FindControlRecursive <HtmlGenericControl>("employeeData");

            Assert.IsFalse(employeeData.Visible, "Expected employeeData control to be visible=false");


            var txtId = page.FindControlRecursive <TextBox>("txtId");

            Assert.IsTrue(txtId.Text == string.Empty, "Expected ID text box to have no value");


            personRepo.Verify(x => x.GetPerson(It.IsAny <int>()), Times.Never());
        }
Beispiel #3
0
        public void DefaultPage_VerifyFooterContent()
        {
            var personRepo   = new Mock <IPersonRepository>();
            var yearProvider = new Mock <IYearProvider>();

            yearProvider.Setup(x => x.CurrentYear).Returns(2000);

            var collection = new ServiceCollection();

            collection.AddScoped((sp) => { return(personRepo.Object); });
            collection.AddScoped((sp) => { return(yearProvider.Object); });

            var provider = new Services.ServiceProvider(collection.BuildServiceProvider());


            WebApplicationProxy.Create(typeof(_Default), provider);

            var page = WebApplicationProxy.GetPageByLocation <_Default>("/default.aspx", collection);

            page.RunToEvent(WebFormEvent.PreRender);

            var pageHtml = page.RenderHtml();

            var parser    = new HtmlParser();
            var document  = parser.Parse(pageHtml);
            var footerDiv = document.QuerySelectorAll("div[class=footer]");

            Assert.IsTrue(footerDiv.Length == 1, "Expected exactly one footer div");
            Assert.IsTrue(footerDiv[0].TextContent == "© 2000", "Value of label was incorrect");
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="target">The tarket entity</param>
        /// <param name="stage">10=validate,20=pre,40=post</param>
        /// <param name="message">Create,Update,Delete,??</param>
        /// <param name="isAsync">false or true, only apply to stage 40</param>
        /// <param name="finalize">Will be executed end of step, regardless of any plugin execution</param>
        /// <param name="onDone">the valide method provided by the test library</param>
        private void ExecuteStep(Microsoft.Xrm.Sdk.Entity target, int stage, string message, bool isAsync, Action finalize, Action onDone)
        {
            if (message != "Create" && stage == 10)
            {
                var key = target.LogicalName + target.Id.ToString();
                this.preImage = this.entities[key].Clone();
            }

            var methods = this.pluginMethodCache.ForPlugin(this.plugin.GetType(), stage, message, target.LogicalName, isAsync, false);

            if (methods.Length > 0)
            {
                var pluginExecutionContext = new Services.PluginExecutionContext(stage, 1, message, target.LogicalName, target.Id, isAsync);
                pluginExecutionContext.InputParameters.Add("Target", target);

                if (message != "Create")
                {
                    var imagePre = this.ResolveImage(target.LogicalName, target.Id, 1, methods, preImage);
                    if (imagePre != null)
                    {
                        var imgName = Kipon.Fake.Xrm.Reflection.PluginMethod.ImageSuffixFor(1, stage, isAsync);
                        pluginExecutionContext.PreEntityImages.Add(imgName, imagePre);
                    }
                }

                if (stage == 40 && message != "Delete")
                {
                    var imagePost = this.ResolveImage(target.LogicalName, target.Id, 2, methods, null);
                    if (imagePost != null)
                    {
                        var imgName = Kipon.Fake.Xrm.Reflection.PluginMethod.ImageSuffixFor(2, stage, isAsync);
                        pluginExecutionContext.PostEntityImages.Add(imgName, imagePost);
                    }
                }

                var serviceProvider = new Services.ServiceProvider(pluginExecutionContext, this, this.plugin.GetType().Assembly);
                this.plugin.Execute(serviceProvider);

                finalize?.Invoke();

                onDone?.Invoke();
            }
            else
            {
                if (onDone != null)
                {
                    throw new Exceptions.UnexpectedEventListenerException(plugin.GetType(), message, stage);
                }
                else
                {
                    finalize?.Invoke();
                }
            }
        }
Beispiel #5
0
        public void DefaultPage_TestPersonDataPopulation()
        {
            var mockPerson = new Data.Entity.Person
            {
                Id          = 5,
                FirstName   = "Joe",
                LastName    = "Brown",
                DateOfBirth = new DateTime(1980, 5, 1)
            };

            var yearProvider = new Mock <IYearProvider>();
            var personRepo   = new Mock <IPersonRepository>();

            personRepo.Setup(d => d.GetPerson(It.IsAny <int>())).Returns(mockPerson);

            var collection = new ServiceCollection();

            collection.AddScoped((sp) => { return(personRepo.Object); });
            collection.AddScoped((sp) => { return(yearProvider.Object); });

            var provider = new Services.ServiceProvider(collection.BuildServiceProvider());


            WebApplicationProxy.Create(typeof(_Default), provider);

            var page = WebApplicationProxy.GetPageByLocation <_Default>("/default.aspx");

            page.RunToEvent(WebFormEvent.PreRender);

            var submitButton = page.FindControlRecursive <Button>("submitButton");

            var postData = new NameValueCollection();

            postData.Add("ctl00$MainContent$txtId", mockPerson.Id.ToString());
            page.MockPostData(postData);
            submitButton.FireEvent("Click", null);


            personRepo.Verify(x => x.GetPerson(It.Is <int>((val) => val == 5)), Times.Once());


            var employeeData = page.FindControlRecursive <HtmlGenericControl>("employeeData");

            Assert.IsTrue(employeeData.Visible, "Expected employeeData control to be visible");

            var LabelId = page.FindControlRecursive <Label>("LabelId");

            Assert.AreEqual <string>(LabelId.Text, mockPerson.Id.ToString());

            var LabelFirstName = page.FindControlRecursive <Label>("LabelFirstName");

            Assert.AreEqual <string>(LabelFirstName.Text, mockPerson.FirstName);

            var LabelLastName = page.FindControlRecursive <Label>("LabelLastName");

            Assert.AreEqual <string>(LabelLastName.Text, mockPerson.LastName);

            var LabelDob = page.FindControlRecursive <Label>("LabelDob");

            Assert.AreEqual <string>(LabelDob.Text, mockPerson.DateOfBirth.ToShortDateString());



            //sut.sub
            var outHTML = page.RenderHtml();
        }