Exemple #1
0
        public CuteService(IOrganizationService service)
        {
            Provider = new CuteProvider
            {
                Type = InstanceType.StandaloneInput
            };

            Original = service;
        }
        public void Serialize_To_XML()
        {
            // Arrange
            var provider = new CuteProvider(Substitute.For<IServiceProvider>());

            // Act
            var result = provider.ToXml();

            // Assert
            result.Should().BeAssignableTo<XmlDocument>();
        }
        public void Serialize_To_Base64String()
        {
            // Arrange
            var provider = new CuteProvider(Substitute.For<IServiceProvider>());

            // Act
            var result = provider.ToBase64String();

            // Assert
            result.Should().BeAssignableTo<string>();
        }
Exemple #4
0
        private static IOrganizationServiceFactory CreateBareInputFactory()
        {
            // Arrange
            var originalProvider = Substitute.For<IServiceProvider>();
            var originalFactory = Substitute.For<IOrganizationServiceFactory>();
            var originalService = Substitute.For<IOrganizationService>();

            originalFactory.CreateOrganizationService(Arg.Any<Guid?>()).Returns(originalService);

            originalProvider.GetService(typeof(IOrganizationServiceFactory)).Returns(originalFactory);

            var provider = new CuteProvider(originalProvider);
            return (IOrganizationServiceFactory)provider.GetService(typeof(IOrganizationServiceFactory));
        }
Exemple #5
0
        public CuteService(CuteProvider provider, Guid? userId)
        {
            Provider = provider;
            UserId = userId;

            if (Provider.Original != null)
            {
                var factory = (IOrganizationServiceFactory)provider.Original.GetService(typeof(IOrganizationServiceFactory));

                Original = factory.CreateOrganizationService(userId);
            }

            if (Provider.Proxy != null)
            {
                Original = this.Provider.Proxy;
            }
        }
        public void Serialize_Deserialize()
        {
            // Arrange
            var inputContext = Substitute.For<IPluginExecutionContext>();
            inputContext.ParentContext.Returns(new CuteContext());
            inputContext.PrimaryEntityName.Returns("account");
            inputContext.MessageName.Returns("Create");

            var provider = Substitute.For<IServiceProvider>();
            provider.GetService(typeof(IPluginExecutionContext)).Returns(inputContext);

            var inputProvider = new CuteProvider(provider);
            inputProvider.Calls.Add(new CuteCall("Create"));
            inputProvider.Calls.Add(new CuteCall("Update"));

            // Act
            var outputProvider = new CuteProvider(inputProvider.ToBase64String());
            var outputContext = (IPluginExecutionContext)outputProvider.GetService(typeof(IPluginExecutionContext));

            // Assert
            outputProvider.Should().NotBeNull();
            outputProvider.Should().BeAssignableTo<CuteProvider>();

            outputProvider.Calls.Should().NotBeNull();
            outputProvider.Calls.Count.Should().Be(inputProvider.Calls.Count);

            outputProvider.Context.Should().NotBeNull();
            outputContext.Should().NotBeNull();

            outputProvider.Context.Should().BeAssignableTo<CuteContext>();
            outputContext.Should().BeAssignableTo<CuteContext>();

            outputProvider.Context.PrimaryEntityName.Should().Be("account");
            outputProvider.Context.MessageName.Should().Be("Create");

            outputContext.PrimaryEntityName.Should().Be("account");
            outputContext.MessageName.Should().Be("Create");

            outputProvider.Original.Should().BeNull();
        }
Exemple #7
0
        private static IServiceProvider CreateTransparentInputProvider()
        {
            var provider = new CuteProvider(Substitute.For<IOrganizationService>());

            provider.Context.MessageName = "ValidMessageName";
            provider.Context.PrimaryEntityName = "ValidEntityName";
            provider.Context.PrimaryEntityId = Guid.NewGuid();

            return provider;
        }
Exemple #8
0
        private static IServiceProvider CreateNoInputProvider()
        {
            var provider = new CuteProvider();

            provider.Context.MessageName = "ValidMessageName";
            provider.Context.PrimaryEntityName = "ValidEntityName";
            provider.Context.PrimaryEntityId = Guid.NewGuid();

            return provider;
        }
Exemple #9
0
        /// <summary>
        /// Compares two objects using Knuth hashes
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            var call = (CuteCall)obj;

            if (call.Message != this.Message)
            {
                return false;
            }

            switch (this.Message)
            {
                case MessageName.Retrieve:
                    {
                        if ((string)Input[0] != (string)call.Input[0])
                        {
                            return false;
                        }

                        if ((Guid)Input[1] != (Guid)call.Input[1])
                        {
                            return false;
                        }

                        var thisOne = (ColumnSet)Input[2];
                        var thatOne = (ColumnSet)call.Input[2];

                        thisOne.ExtensionData = null;
                        thatOne.ExtensionData = null;

                        return Serialization.Hash<ColumnSet>(thatOne) == Serialization.Hash<ColumnSet>(thisOne);
                    }

                case MessageName.RetrieveMultiple:
                    {
                        if (Input[0] is QueryExpression)
                        {
                            var thisOne = (QueryExpression)Input[0];
                            var thatOne = (QueryExpression)call.Input[0];

                            thisOne.PageInfo = null;
                            thatOne.PageInfo = null;

                            return Serialization.Hash<QueryExpression>(thatOne) == Serialization.Hash<QueryExpression>(thisOne);
                        }
                    }

                    break;
            }

            var types = new CuteProvider().Types;

            return Serialization.Hash(call.Input, types) == Serialization.Hash(Input, types);
        }
Exemple #10
0
 public CuteFactory(CuteProvider provider)
 {
     Provider = provider;
 }
Exemple #11
0
 public void Setup()
 {
     // Arrange
     this.provider = new CuteProvider();
 }
Exemple #12
0
        private static IOrganizationService CreateWrappedInputService()
        {
            var originalService = ServiceTestCases.CreateBareInputService();

            var provider = new CuteProvider(((CuteService)originalService).Provider);
            return ((IOrganizationServiceFactory)provider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(Guid.Empty);
        }
Exemple #13
0
        private static IOrganizationService CreateSerializedInputService()
        {
            var service = ServiceTestCases.CreateBareInputService();

            // Calling methods to fill calls stack
            service.Create(new Entity());
            try
            {
                service.Create(new Entity("fail"));
            }
            catch (Exception)
            {
            }

            service.Delete(string.Empty, Guid.Empty);
            try
            {
                service.Delete("fail", Guid.Empty);
            }
            catch (Exception)
            {
            }

            service.Retrieve(string.Empty, Guid.Empty, new ColumnSet());
            service.RetrieveMultiple(new QueryExpression());
            service.Execute(new OrganizationRequest());

            // Recreating provider from serialized one
            var provider = new CuteProvider(((CuteService)service).Provider.ToBase64String());
            return ((IOrganizationServiceFactory)provider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(Guid.Empty);
        }
Exemple #14
0
        private static IOrganizationService CreateNoInputService()
        {
            // Creating provider from scratch
            var originalProvider = new CuteProvider();

            originalProvider.Calls.Add(new CuteCall(MessageName.Create, new[] { new Entity() }, ServiceTestCases.expectedResultCreate));
            originalProvider.Calls.Add(new CuteCall(MessageName.Create, new[] { new Entity("fail") }, new InvalidPluginExecutionException()));

            originalProvider.Calls.Add(new CuteCall(MessageName.Delete, new object[] { string.Empty, Guid.Empty }));
            originalProvider.Calls.Add(new CuteCall(MessageName.Delete, new object[] { "fail", Guid.Empty }, new InvalidPluginExecutionException()));

            originalProvider.Calls.Add(new CuteCall(MessageName.Retrieve, new object[] { string.Empty, Guid.Empty, new ColumnSet() }, ServiceTestCases.expectedResultRetrieve));
            originalProvider.Calls.Add(new CuteCall(MessageName.RetrieveMultiple, new object[] { new QueryExpression() }, ServiceTestCases.expectedResultRetrieveMultiple));
            originalProvider.Calls.Add(new CuteCall(MessageName.Execute, new object[] { new OrganizationRequest() }, ServiceTestCases.expectedResultExecute));

            return ((IOrganizationServiceFactory)originalProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(Guid.Empty);
        }