public void Should_Not_Change_Context_Objects_Without_Update()
        {
            var entityId = Guid.NewGuid();
            var context = new XrmFakedContext();
            var service = context.GetOrganizationService();

            context.Initialize(new[] {
                new Entity ("account")
                {
                    Id = entityId,
                    Attributes = new AttributeCollection
                    {
                        { "accountname", "Adventure Works" }
                    }
                }
            });

            var firstRetrieve = service.Retrieve("account", entityId, new ColumnSet(true));
            var secondRetrieve = service.Retrieve("account", entityId, new ColumnSet(true));

            firstRetrieve["accountname"] = "Updated locally";

            Assert.Equal("Updated locally", firstRetrieve["accountname"]);
            Assert.Equal("Adventure Works", secondRetrieve["accountname"]);
        }
예제 #2
0
        public void Should_update_an_entity_when_calling_update()
        {
            var ctx = new XrmFakedContext();
            var logSystem = A.Fake<IDetailedLog>();
            var service = ctx.GetOrganizationService();

            //Arrange
            var contact = new Entity("contact") { Id = Guid.NewGuid() };
            contact["fullname"] = "Lionel Messi";

            ctx.Initialize(new Entity[]
            {
                contact
            });

            //Act
            var contactToUpdate = new Entity("contact") { Id = contact.Id };
            contactToUpdate["fullname"] = "Luis Suárez";

            var actions = new Actions(logSystem, service);
            actions.Update(contactToUpdate);

            //Assert
            var contacts = ctx.CreateQuery("contact").ToList();
            Assert.Equal(1, contacts.Count);
            Assert.Equal(contacts[0]["fullname"], "Luis Suárez");
        }
예제 #3
0
        // Test class constructor
        public AccountTests()
        {
            // Create fake service
            fakeContext = new XrmFakedContext();
            fakeService = fakeContext.GetOrganizationService();

            // Create real service
            realContext = new MyContext("XRM");
            realService = realContext.GetOrganizationService();
        }
예제 #4
0
        public void Should_create_a_new_entity_when_calling_create()
        {
            var ctx = new XrmFakedContext();
            var logSystem = A.Fake<IDetailedLog>();
            var service = ctx.GetOrganizationService();

            //Arrange
            var actions = new Actions(logSystem, service);
            var contact = new Entity("contact");
            contact["fullname"] = "Lionel Messi";

            //Act
            actions.Create(contact);

            //Assert
            var contactCreated = ctx.CreateQuery("contact").FirstOrDefault();
            Assert.NotNull(contactCreated);
            Assert.Equal(contactCreated["fullname"], "Lionel Messi");
        }
예제 #5
0
        public void Should_delete_an_entisting_record_when_calling_delete()
        {
            var ctx = new XrmFakedContext();
            var logSystem = A.Fake<IDetailedLog>();
            var service = ctx.GetOrganizationService();

            //Arrange
            var contact = new Entity("contact") { Id = Guid.NewGuid() };
            contact["fullname"] = "Lionel Messi";

            ctx.Initialize(new Entity[]
            {
                contact
            });

            //Act
            var actions = new Actions(logSystem, service);
            actions.Delete(contact.Id, "contact");

            //Assert
            var contacts = ctx.CreateQuery("contact").ToList();
            Assert.Equal(0, contacts.Count);
        }
        public void Should_Not_Change_Context_Objects_Without_Update_And_Retrieve_Multiple()
        {
            var entityId = Guid.NewGuid();
            var context = new XrmFakedContext();
            var service = context.GetOrganizationService();

            context.Initialize(new[] {
                new Account
                {
                    Id = entityId,
                    Name = "Adventure Works"
                }
            });

            Account firstRetrieve, secondRetrieve = null;
            using (var ctx = new XrmServiceContext(service))
            {
                firstRetrieve = ctx.CreateQuery<Account>()
                                    .Where(a => a.AccountId == entityId)
                                    .FirstOrDefault();

            }

            using (var ctx = new XrmServiceContext(service))
            {
                secondRetrieve = ctx.CreateQuery<Account>()
                                    .Where(a => a.AccountId == entityId)
                                    .FirstOrDefault();

            }

            firstRetrieve.Name = "Updated locally";

            Assert.False(firstRetrieve == secondRetrieve);
            Assert.Equal("Updated locally", firstRetrieve.Name);
            Assert.Equal("Adventure Works", secondRetrieve.Name);
        }