Exemplo n.º 1
0
        public async Task CreateAsync_When_Present_Money_Property_Then_Ok()
        {
            const string propertyName  = "budgetamount";
            const double propertyValue = 123.15d;

            var opportunity = new Entity("opportunity")
            {
                [propertyName] = propertyValue
            };

            EntityReference opportunityRef = null;

            try
            {
                var opportunityId = await CrmClient.CreateAsync(opportunity);

                opportunityId.Should().NotBeEmpty();

                opportunityRef = new EntityReference("opportunity", opportunityId);

                var opportunityFormDb =
                    await CrmClient.RetrieveAsync(opportunityRef, QueryOptions.Select(propertyName));

                var actualBudged = opportunityFormDb.GetAttributeValue <double>(propertyName);
                actualBudged.Should().Be(propertyValue);
            }
            finally
            {
                if (opportunityRef != null)
                {
                    await CrmClient.DeleteAsync(opportunityRef);
                }
            }
        }
Exemplo n.º 2
0
        public async Task CreateAsync_When_Present_DateOnly_Property_Then_Ok()
        {
            const string propertyName  = "birthdate";
            var          propertyValue = new DateTime(2020, 09, 17);

            var contact = new Entity("contact");

            contact.SetAttributeValue(propertyName, propertyValue);

            EntityReference contactRef = default;

            try
            {
                var id = await CrmClient.CreateAsync(contact);

                id.Should().NotBeEmpty();

                contactRef = new EntityReference("contact", id);
                var contactFromDb = await CrmClient.RetrieveAsync(contactRef, QueryOptions.Select(propertyName));

                var actualValue = contactFromDb.GetAttributeValue <DateTime>(propertyName);
                actualValue.Should().Be(propertyValue);
            }
            finally
            {
                if (contactRef != null)
                {
                    await CrmClient.DeleteAsync(contactRef);
                }
            }
        }
        public async Task RetrieveAsync_When_DateOnly_Attribute_Then_Correct_DateValue()
        {
            var contact = new Entity("contact")
            {
                ["birthdate"] = new DateTime(1986, 12, 21, 00, 00, 00)
            };

            var id = await CrmClient.CreateAsync(contact);

            var contactReference = new EntityReference("contact", id);
            var contactFields    = QueryOptions.Select("birthdate");

            var entity = await CrmClient.RetrieveAsync(contactReference, contactFields);

            try
            {
                entity.Should().NotBeNull();

                var birthDate = entity.GetAttributeValue <DateTime>("birthdate");
                birthDate.Date.Should().Be(new DateTime(1986, 12, 21));

                birthDate.TimeOfDay.Should().Be(new TimeSpan());

                birthDate.Kind.Should().Be(DateTimeKind.Unspecified);
            }
            finally
            {
                if (!Guid.Empty.Equals(id))
                {
                    await CrmClient.DeleteAsync(new EntityReference("contact", id));
                }
            }
        }
        public async Task ExecuteAsync_WinOpportunityRequest_When_Caller_Is_Null_Then_Ok()
        {
            var opportunityId        = new Guid("{5D0E46CA-49F1-EA11-AAF2-005056B42CD8}");
            var opportunityEntityRef = new EntityReference(OpportunityEntityName, opportunityId);

            await CrmClient.CreateAsync(new Entity(OpportunityEntityName, opportunityId));

            var opportunityCloseEntity = new Entity("opportunityclose");

            opportunityCloseEntity.SetAttributeValue("subject", "Won Opportunity");
            opportunityCloseEntity.SetAttributeValue("opportunityid", opportunityEntityRef);

            var action = new WinOpportunityRequest()
            {
                OpportunityClose = opportunityCloseEntity,
                Status           = 3
            };

            try
            {
                await CrmClient.ExecuteAsync(action);
            }
            finally
            {
                await CrmClient.DeleteAsync(opportunityEntityRef);
            }
        }
Exemplo n.º 5
0
        public async Task CreateAsync_When_Present_DateTime_Property_Then_Ok()
        {
            const string propertyName  = "finaldecisiondate";
            var          propertyValue = DateTime.Now.Date.ToUniversalTime();

            var opportunity = new Entity("opportunity");

            opportunity.SetAttributeValue(propertyName, propertyValue);

            EntityReference opportunityRef = default;

            try
            {
                var opportunityId = await CrmClient.CreateAsync(opportunity);

                opportunityId.Should().NotBeEmpty();

                opportunityRef = new EntityReference("opportunity", opportunityId);
                var opportunityFormDb =
                    await CrmClient.RetrieveAsync(opportunityRef, QueryOptions.Select(propertyName));

                var actualDate = opportunityFormDb.GetAttributeValue <DateTime>(propertyName);
                actualDate.Should().Be(propertyValue);
            }
            finally
            {
                if (opportunityRef != null)
                {
                    await CrmClient.DeleteAsync(opportunityRef);
                }
            }
        }
        public async Task RetrieveAsync_When_Expand_Then_Retrieved_NestedEntity_Correct()
        {
            var account = new Account()
            {
                ["primarycontactid"] = new Entity("contact")
                {
                    ["firstname"] = "[Test] First Name",
                    ["lastname"]  = "[Test] Last Name",
                }
            };

            var accountId = await CrmClient.CreateAsync(account);

            var accountFiled = new[]
            {
                "*" // Only not NULL attributes
            };

            var contactFiled = new[]
            {
                "ownerid", "statecode", "firstname", "fullname", "birthdate"
            };

            var options = QueryOptions
                          .Select(accountFiled)
                          .Expand("primarycontactid", contactFiled);

            EntityReference accountReference = Account.Reference(accountId);
            EntityReference contactRef       = null;

            try
            {
                var complexAccountEntity = await CrmClient.RetrieveAsync(accountReference, options);

                complexAccountEntity.Should().NotBeNull();
                var contactEntity = complexAccountEntity.GetAttributeValue <Entity>("primarycontactid");

                contactEntity
                .Should().NotBeNull();
                contactEntity.GetAttributeValue <string>("firstname")
                .Should().Be("[Test] First Name");

                contactEntity.Id
                .Should().NotBeEmpty();

                contactRef = contactEntity.ToEntityReference();
            }
            finally
            {
                await CrmClient.DeleteAsync(accountReference);

                if (contactRef != null)
                {
                    await CrmClient.DeleteAsync(contactRef);
                }
            }
        }
Exemplo n.º 7
0
        public async Task CreateAsync_When_Empty_Entity_Then_ReturnId()
        {
            var entity = new Entity("contact");

            var id = await CrmClient.CreateAsync(entity);

            try
            {
                id.Should().NotBeEmpty();
            }
            finally
            {
                if (!Guid.Empty.Equals(id))
                {
                    await CrmClient.DeleteAsync(new EntityReference("contact", id));
                }
            }
        }
Exemplo n.º 8
0
        public async Task CreateAsync_When_Present_PrimaryIdAttribute_Then_ReturnId()
        {
            var entity = new Entity("account")
            {
                ["accountid"] = SetupBase.EntityId
            };

            var id = await CrmClient.CreateAsync(entity);

            try
            {
                id.Should().NotBeEmpty();
            }
            finally
            {
                if (!Guid.Empty.Equals(id))
                {
                    await CrmClient.DeleteAsync(new EntityReference("account", id));
                }
            }
        }
Exemplo n.º 9
0
        public async Task CreateAsync_When_Present_CustomerProperty_Then_Ok()
        {
            EntityReference contactRef     = new EntityReference("contact", SetupBase.EntityId);
            EntityReference opportunityRef = default;

            try
            {
                // Create Contact
                await CrmClient.CreateAsync(new Entity("contact", SetupBase.EntityId));

                var opportunity = new Entity("opportunity")
                {
                    ["customerid_contact"] = contactRef
                };

                var opportunityId = await CrmClient.CreateAsync(opportunity);

                opportunityId.Should().NotBeEmpty();

                opportunityRef = new EntityReference("opportunity", opportunityId);

                var opportunityFormDb =
                    await CrmClient.RetrieveAsync(opportunityRef, QueryOptions.Select("customerid"));

                var customerRef = opportunityFormDb.GetAttributeValue <EntityReference>("customerid");
                customerRef.Should().NotBeNull();
                customerRef.Should().BeEquivalentTo(contactRef);
            }
            finally
            {
                if (opportunityRef != null)
                {
                    await CrmClient.DeleteAsync(opportunityRef);
                }

                // Delete Contact
                await CrmClient.DeleteAsync(contactRef);
            }
        }