public void AssignEntityOk()
        {
            var objectRef = GetRef("entityName");
            var ownerRef  = GetRef("entityName");

            AdminOrganizationService.Setup(s => s.Execute(It.IsAny <AssignRequest>())).Callback <OrganizationRequest>(r =>
            {
                Assert.IsInstanceOfType(r, typeof(AssignRequest));

                var request = r as AssignRequest;

                Assert.AreEqual(request.Target, objectRef);
                Assert.AreEqual(request.Assignee, ownerRef);
            }).Returns(new AssignResponse());

            Service.AssignEntity(objectRef, ownerRef);

            AdminOrganizationService.Setup(s => s.Execute(It.IsAny <AssignRequest>())).Callback <OrganizationRequest>(r =>
            {
                Assert.IsInstanceOfType(r, typeof(AssignRequest));

                var request = r as AssignRequest;

                Assert.AreEqual(request.Assignee.Id, ServiceContext.InitiatingUserId);
            }).Returns(new AssignResponse());

            Service.AssignEntity(objectRef, null);
        }
Esempio n. 2
0
        public ICollection <EntityReference> GetSubContactRefs(EntityReference accountRef)
        {
            var query = new QueryExpression(ContactDefinition.EntityName);

            query.ColumnSet.AddColumn(ContactDefinition.Columns.Id);

            query.Criteria.AddCondition(ContactDefinition.Columns.ParentCustomerId, ConditionOperator.Equal, accountRef.Id);

            return(AdminOrganizationService.RetrieveAll(query).Select(e => e.ToEntityReference()).ToList());
        }
        public void RetrieveOk()
        {
            var entityRef = GetRef("name");
            var entity    = new Entity();
            var columns   = new string[] { "column1", "column2" };

            AdminOrganizationService.Setup(s => s.Execute(It.IsAny <OrganizationRequest>())).Callback <OrganizationRequest>(r =>
            {
                var request = r as RetrieveRequest;
                if (request == null)
                {
                    Assert.Fail("Should be a RetrieveRequest");
                }

                Assert.AreEqual <EntityReference>(request.Target, entityRef);

                for (var i = 0; i < columns.Length; i++)
                {
                    Assert.AreEqual <string>(request.ColumnSet.Columns[i], columns[i]);
                }
            }).Returns(new RetrieveResponse()
            {
                ["Entity"] = entity
            });

            var result = Service.Retrieve(entityRef, columns);

            Assert.AreEqual(result, entity);

            AdminOrganizationService.Setup(s => s.Execute(It.IsAny <OrganizationRequest>())).Callback <OrganizationRequest>(r =>
            {
                var request = r as RetrieveRequest;
                if (request == null)
                {
                    Assert.Fail("Should be a RetrieveRequest");
                }

                Assert.AreEqual <EntityReference>(request.Target, entityRef);

                Assert.AreEqual <bool>(request.ColumnSet.AllColumns, true);
            }).Returns(new RetrieveResponse()
            {
                ["Entity"] = entity
            });

            result = Service.Retrieve(entityRef, true);

            Assert.AreEqual(result, entity);
        }
        public void CreateOk()
        {
            var entity = new Entity();
            var id1    = Guid.NewGuid();
            var id2    = Guid.NewGuid();

            OrganizationService.Setup(s => s.Create(It.IsAny <Entity>())).Callback <Entity>(e =>
            {
                Assert.AreEqual <Entity>(e, entity);
            }).Returns(id1);

            AdminOrganizationService.Setup(s => s.Create(It.IsAny <Entity>())).Callback <Entity>(e =>
            {
                Assert.AreEqual <Entity>(e, entity);
            }).Returns(id2);

            Assert.AreEqual(id1, Service.Create(entity, false));
            Assert.AreEqual(id2, Service.Create(entity, true));
        }
        public void DeleteOk()
        {
            var name = "test";
            var id1  = Guid.NewGuid();
            var id2  = Guid.NewGuid();

            OrganizationService.Setup(s => s.Delete(It.IsAny <string>(), It.IsAny <Guid>())).Callback <string, Guid>((entityName, id) =>
            {
                Assert.AreEqual <string>(name, entityName);
                Assert.AreEqual <Guid>(id1, id);
            });
            AdminOrganizationService.Setup(s => s.Delete(It.IsAny <string>(), It.IsAny <Guid>())).Callback <string, Guid>((entityName, id) =>
            {
                Assert.AreEqual <string>(name, entityName);
                Assert.AreEqual <Guid>(id2, id);
            });

            Service.Delete(name, id1, false);
            Service.Delete(name, id2, true);
        }
        public void UpdateOk()
        {
            var entity = new Entity();

            entity.Id = Guid.NewGuid();

            OrganizationService.Setup(s => s.Update(It.IsAny <Entity>())).Callback <Entity>(e =>
            {
                Assert.ReferenceEquals(e, entity);
            });

            AdminOrganizationService.Setup(s => s.Update(It.IsAny <Entity>())).Callback <Entity>(e =>
            {
                Assert.ReferenceEquals(e, entity);
            });

            Service.Update(entity);

            OrganizationService.Verify(s => s.Update(It.IsAny <Entity>()));

            Service.Update(entity, true);

            AdminOrganizationService.Verify(s => s.Update(It.IsAny <Entity>()));
        }