示例#1
0
        public void Execute_GivenHasContructorWithInputs_ShouldReturnCorrectConstructorName()
        {
            //---------------Set up test pack-------------------
            var type          = typeof(Human);
            var assembly      = type.Assembly;
            var namespaceItem = new NamespaceItem()
            {
                AssemblyLocation = assembly.Location,
                AssemblyName     = assembly.FullName,
                FullName         = type.FullName,
            };
            var pluginSource = new PluginSource()
            {
                AssemblyName     = type.AssemblyQualifiedName,
                AssemblyLocation = assembly.Location,
            };

            var pluginSourceDefinition = new PluginSourceDefinition();
            var serializeToJson        = pluginSourceDefinition.SerializeToJsonStringBuilder();
            var nameSpace   = namespaceItem.SerializeToJsonStringBuilder();
            var resourceCat = new Mock <IResourceCatalog>();

            resourceCat.Setup(catalog => catalog.GetResource <PluginSource>(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .Returns(pluginSource);
            var FetchPluginConstructors = new FetchPluginConstructors(resourceCat.Object);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var mock          = new Mock <IWorkspace>();
            var stringBuilder = FetchPluginConstructors.Execute(new Dictionary <string, StringBuilder>()
            {
                { "source", serializeToJson },
                { "namespace", nameSpace },
            },
                                                                mock.Object);
            //---------------Test Result -----------------------
            var executeMessage      = stringBuilder.DeserializeToObject <ExecuteMessage>();
            var deserializeToObject = executeMessage.Message.DeserializeToObject <List <IPluginConstructor> >();

            Assert.AreEqual(3, deserializeToObject.Count);

            var          pluginConstructor1 = deserializeToObject[1];
            var          constructorName1   = pluginConstructor1.ConstructorName;
            const string expectedName1      = ".ctor (System.String)";

            Assert.AreEqual(expectedName1, constructorName1);

            var          pluginConstructor0 = deserializeToObject[0];
            var          constructorName0   = pluginConstructor0.ConstructorName;
            const string expectedName0      = ".ctor ";

            Assert.AreEqual(expectedName0, constructorName0);
            var          pluginConstructor2 = deserializeToObject[2];
            var          constructorName2   = pluginConstructor2.ConstructorName;
            const string expectedName2      = ".ctor (System.String,System.String,TestingDotnetDllCascading.Food)";

            Assert.AreEqual(expectedName2, constructorName2);
        }
示例#2
0
        public void Execute_GivenHasContructorWithInputs_ShouldReturnCorrectInputs()
        {
            //---------------Set up test pack-------------------
            var type          = typeof(Human);
            var assembly      = type.Assembly;
            var namespaceItem = new NamespaceItem()
            {
                AssemblyLocation = assembly.Location,
                AssemblyName     = assembly.FullName,
                FullName         = type.FullName,
            };
            var pluginSource = new PluginSource()
            {
                AssemblyName     = type.AssemblyQualifiedName,
                AssemblyLocation = assembly.Location,
            };

            var pluginSourceDefinition = new PluginSourceDefinition();
            var serializeToJson        = pluginSourceDefinition.SerializeToJsonStringBuilder();
            var nameSpace   = namespaceItem.SerializeToJsonStringBuilder();
            var resourceCat = new Mock <IResourceCatalog>();

            resourceCat.Setup(catalog => catalog.GetResource <PluginSource>(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .Returns(pluginSource);
            var FetchPluginConstructors = new FetchPluginConstructors(resourceCat.Object);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var mock          = new Mock <IWorkspace>();
            var stringBuilder = FetchPluginConstructors.Execute(new Dictionary <string, StringBuilder>()
            {
                { "source", serializeToJson },
                { "namespace", nameSpace },
            },
                                                                mock.Object);
            //---------------Test Result -----------------------
            var executeMessage      = stringBuilder.DeserializeToObject <ExecuteMessage>();
            var deserializeToObject = executeMessage.Message.DeserializeToObject <List <IPluginConstructor> >();

            Assert.AreEqual(3, deserializeToObject.Count);

            var pluginConstructor = deserializeToObject[1];
            var count             = pluginConstructor.Inputs.Count;

            Assert.AreEqual(1, count);
            var serviceInput  = pluginConstructor.Inputs[0];
            var name          = serviceInput.Name;
            var emptyIsNull   = serviceInput.EmptyToNull;
            var requiredField = serviceInput.IsRequired;
            var value         = serviceInput.Value;
            var typeName      = serviceInput.TypeName;

            Assert.AreEqual("name", name);
            Assert.AreEqual(false, emptyIsNull);
            Assert.AreEqual(true, requiredField);
            Assert.IsTrue(string.IsNullOrEmpty(value));
            Assert.AreEqual(typeof(string), Type.GetType(typeName));
        }
示例#3
0
        public void Execute_GivenTestInputs_ShouldReturnConstructorList()
        {
            //---------------Set up test pack-------------------
            var type          = typeof(Human);
            var assembly      = type.Assembly;
            var namespaceItem = new NamespaceItem()
            {
                AssemblyLocation = assembly.Location,
                AssemblyName     = assembly.FullName,
                FullName         = type.FullName,
            };
            var pluginSource = new PluginSource()
            {
                AssemblyName     = type.AssemblyQualifiedName,
                AssemblyLocation = assembly.Location,
            };

            var pluginSourceDefinition = new PluginSourceDefinition();
            var serializeToJson        = pluginSourceDefinition.SerializeToJsonStringBuilder();
            var nameSpace   = namespaceItem.SerializeToJsonStringBuilder();
            var resourceCat = new Mock <IResourceCatalog>();

            resourceCat.Setup(catalog => catalog.GetResource <PluginSource>(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .Returns(pluginSource);
            var FetchPluginConstructors = new FetchPluginConstructors(resourceCat.Object);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var mock          = new Mock <IWorkspace>();
            var stringBuilder = FetchPluginConstructors.Execute(new Dictionary <string, StringBuilder>()
            {
                { "source", serializeToJson },
                { "namespace", nameSpace },
            },
                                                                mock.Object);
            //---------------Test Result -----------------------
            var executeMessage      = stringBuilder.DeserializeToObject <ExecuteMessage>();
            var deserializeToObject = executeMessage.Message.DeserializeToObject <List <IPluginConstructor> >();

            Assert.AreEqual(3, deserializeToObject.Count);
        }
示例#4
0
        public void Execute_GivenHasError_ShouldReturnErrorState()
        {
            //---------------Set up test pack-------------------
            var type          = typeof(Human);
            var assembly      = type.Assembly;
            var namespaceItem = new NamespaceItem()
            {
                AssemblyLocation = assembly.Location,
                AssemblyName     = assembly.FullName,
                FullName         = type.FullName,
            };


            var pluginSourceDefinition = new PluginSourceDefinition();
            var serializeToJson        = pluginSourceDefinition.SerializeToJsonStringBuilder();
            var nameSpace   = namespaceItem.SerializeToJsonStringBuilder();
            var resourceCat = new Mock <IResourceCatalog>();

            resourceCat.Setup(catalog => catalog.GetResource <PluginSource>(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .Throws(new Exception("error"));
            var FetchPluginConstructors = new FetchPluginConstructors(resourceCat.Object);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var mock          = new Mock <IWorkspace>();
            var stringBuilder = FetchPluginConstructors.Execute(new Dictionary <string, StringBuilder>()
            {
                { "source", serializeToJson },
                { "namespace", nameSpace },
            },
                                                                mock.Object);
            //---------------Test Result -----------------------
            var executeMessage = stringBuilder.DeserializeToObject <ExecuteMessage>();

            Assert.IsTrue(executeMessage.HasError);
            Assert.AreEqual("error", executeMessage.Message.ToString());
        }