Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }