Exemple #1
0
        public void Should_Retrieve_Records_By_Given_Find()
        {
            // Arrange
            var sampleView = new SavedView()
            {
                Name     = "Sample",
                Id       = Guid.NewGuid(),
                FetchXML = @"
<fetch version=""1.0"" output-format=""xml-platform"" mapping=""logical"" distinct=""false"">
  <entity name=""contact"">
    <attribute name=""emailaddress1"" />
    <attribute name=""lastname"" />
    <attribute name=""firstname"" />
    <attribute name=""address1_telephone1"" />
    <attribute name=""contactid"" />
  </entity>
</fetch>",
            };
            var person = new Person()
            {
                Id        = Guid.NewGuid(),
                FirstName = "Billy",
                LastName  = "Bob"
            };

            var fakedContext = new XrmFakedContext();

            fakedContext.Initialize(new List <Entity>()
            {
                person,
                sampleView,
            });

            var service        = fakedContext.GetOrganizationService();
            var serviceContext = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service);

            // Act
            var helper  = new CFApiHelper();
            var results = CFApiHelper.GetPeopleFromFetch(
                serviceContext,
                service,
                sampleView.Name);

            // Assert
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(results.FirstOrDefault().Id, person.Id);
        }
Exemple #2
0
        public void Should_Throw_If_Wrong_Count_of_Finds_Found()
        {
            var fakedContext = new XrmFakedContext();

            // Initialize Empty CRM
            fakedContext.Initialize(new List <Entity>());

            var service        = fakedContext.GetOrganizationService();
            var serviceContext = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service);

            // Act
            var helper    = new CFApiHelper();
            var exception = Assert.Throws <Exception>(() =>
                                                      CFApiHelper.GetPeopleFromFetch(serviceContext, service, "foo"));

            Assert.That(exception.Message, Is.EqualTo("Expected exactly one Advanced Find name \"foo\", but found 0"));
        }