public WhenCallingReadCommittedByIdOnAnItemDeletedInTheCurrentSession()
        {
            // Given
            var testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingReadCommittedByIdOnAnItemDeletedInTheCurrentSession));

            this.carId = Guid.NewGuid();
            var existingCar = new Car
            {
                id     = this.carId,
                Active = false,
                Make   = "Volvo"
            };

            testHarness.AddToDatabase(existingCar);

            testHarness.DataStore.DeleteHardById <Car>(this.carId).Wait();

            // When
            var document = testHarness.DataStore.Advanced.ReadCommittedById <Car>(this.carId).Result;

            try
            {
                this.carFromDatabase = document; //this approach is for Azure
            }
            catch (Exception)
            {
                this.carFromDatabase = JsonConvert.DeserializeObject <Car>(JsonConvert.SerializeObject(document));
            }
        }
        public WhenCallingReadActiveByIdOnAnItemAddedInTheCurrentSession()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingReadActiveByIdOnAnItemAddedInTheCurrentSession));

            var carId       = Guid.NewGuid();
            var existingCar = new Car
            {
                id     = carId,
                Active = true,
                Make   = "Volvo"
            };

            this.testHarness.AddToDatabase(existingCar);

            var newCarId = Guid.NewGuid();

            this.testHarness.DataStore.Create(
                new Car
            {
                id     = newCarId,
                Active = true,
                Make   = "Ford"
            }).Wait();

            this.newCarFromSession = this.testHarness.DataStore.ReadActiveById <Car>(newCarId).Result;
        }
        public WhenCallingReadActiveByIdOnAnActiveItem()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingReadActiveByIdOnAnActiveItem));

            this.activeCarId = Guid.NewGuid();
            var activeExistingCar = new Car
            {
                id     = this.activeCarId,
                Active = true,
                Make   = "Volvo"
            };

            var inactiveCarId       = Guid.NewGuid();
            var inactiveExistingCar = new Car
            {
                id     = inactiveCarId,
                Active = false,
                Make   = "Jeep"
            };

            this.testHarness.AddToDatabase(activeExistingCar);
            this.testHarness.AddToDatabase(inactiveExistingCar);

            // When
            this.activeCarFromDatabase = this.testHarness.DataStore.ReadActiveById <Car>(this.activeCarId).Result;
        }
Esempio n. 4
0
        public WhenChangingTheItemPassedIntoUpdate()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenChangingTheItemPassedIntoUpdate));

            this.carId = Guid.NewGuid();
            var existingCar = new Car
            {
                id   = this.carId,
                Make = "Volvo"
            };

            this.testHarness.AddToDatabase(existingCar);

            //read from db to pickup changes to properties made by datastore oncreate
            var existingCarFromDb = this.testHarness.DataStore.ReadActiveById <Car>(this.carId).Result;

            existingCarFromDb.Make = "Ford";

            this.testHarness.DataStore.Update(existingCarFromDb).Wait();

            //change the id before committing, if not cloned this would cause the item not to be found
            existingCarFromDb.id = Guid.NewGuid();

            //When
            this.testHarness.DataStore.CommitChanges().Wait();
        }
        public WhenCallingReadActive()
        {
            // Given
            var testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingReadActive));

            var activeCarId       = Guid.NewGuid();
            var activeExistingCar = new Car
            {
                id   = activeCarId,
                Make = "Volvo"
            };

            var inactiveCarId       = Guid.NewGuid();
            var inactiveExistingCar = new Car
            {
                id     = inactiveCarId,
                Active = false,
                Make   = "Jeep"
            };

            testHarness.AddToDatabase(activeExistingCar);
            testHarness.AddToDatabase(inactiveExistingCar);

            // When
            this.activeCarFromDatabase   = testHarness.DataStore.ReadActive <Car>(car => car.id == activeCarId).Result.SingleOrDefault();
            this.inactiveCarFromDatabase = testHarness.DataStore.ReadActive <Car>(car => car.id == inactiveCarId).Result.SingleOrDefault();
        }
        public WhenDocumentsAreCreatedWithClassNameAsThePartitionKey()
        {
            //Given
            var collectionName = nameof(WhenDocumentsAreCreatedWithClassNameAsThePartitionKey);

            var docDbCollectionSettings = DocDbCollectionSettings.Create(collectionName, DocDbCollectionSettings.PartitionKeyTypeEnum.ClassName);

            this.testHarness = TestHarnessFunctions.GetDocumentDbTestHarness(collectionName, docDbCollectionSettings);

            //When
            for (var i = 0; i < 5; i++)
            {
                var car = new Car
                {
                    id   = Guid.NewGuid(),
                    Make = "Saab"
                };

                this.testHarness.DataStore.Create(car).Wait();
            }
            this.testHarness.DataStore.CommitChanges().Wait();

            //HACK: runtime manual override
            docDbCollectionSettings.EnableCrossParitionQueries = false;
        }
Esempio n. 7
0
        public WhenCallingUpdateGiven1Of2ItemsExists()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingUpdateGiven1Of2ItemsExists));

            var volvoId = Guid.NewGuid();

            this.testHarness.AddToDatabase(
                new Car
            {
                id   = volvoId,
                Make = "Volvo"
            });

            var fordId = Guid.NewGuid();

            this.testHarness.AddToDatabase(
                new Car
            {
                id   = fordId,
                Make = "Ford"
            });

            //When
            this.result = this.testHarness.DataStore.UpdateWhere <Car>(c => c.Make == "Volvo", car => { }).Result;
            this.testHarness.DataStore.CommitChanges().Wait();
        }
Esempio n. 8
0
        public WhenCallingExistsOnAnInactiveItem()
        {
            // Given
            var testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingExistsOnAnInactiveItem));

            var activeCarId       = Guid.NewGuid();
            var activeExistingCar = new Car
            {
                id   = activeCarId,
                Make = "Volvo"
            };

            var inactiveCarId       = Guid.NewGuid();
            var inactiveExistingCar = new Car
            {
                id     = inactiveCarId,
                Active = false,
                Make   = "Jeep"
            };

            testHarness.AddToDatabase(activeExistingCar);
            testHarness.AddToDatabase(inactiveExistingCar);

            // When
            this.activeCarExists   = testHarness.DataStore.Exists(activeCarId).Result;
            this.inactiveCarExists = testHarness.DataStore.Exists(inactiveCarId).Result;
        }
Esempio n. 9
0
        public WhenCallingRead()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingRead));

            var activeCarId       = Guid.NewGuid();
            var activeExistingCar = new Car
            {
                id   = activeCarId,
                Make = "Volvo"
            };

            var inactiveCarId       = Guid.NewGuid();
            var inactiveExistingCar = new Car
            {
                id     = inactiveCarId,
                Active = false,
                Make   = "Volvo"
            };

            this.testHarness.AddToDatabase(activeExistingCar);
            this.testHarness.AddToDatabase(inactiveExistingCar);

            // When
            this.carsFromDatabase = this.testHarness.DataStore.Read <Car>(car => car.Make == "Volvo").Result;
        }
        public WhenCallingReadActiveByIdOnAnItemThatDoesNotExist()
        {
            // Given
            var testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingReadActiveByIdOnAnItemThatDoesNotExist));

            // When
            this.activeCarFromDatabase = testHarness.DataStore.ReadActiveById <Car>(Guid.NewGuid()).Result;
        }
Esempio n. 11
0
        public WhenCallingReadActiveAndNoItemsMatchThePredicate()
        {
            // Given
            var testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingReadActiveAndNoItemsMatchThePredicate));

            // When
            this.carsFromDatabase = testHarness.DataStore.ReadActive <Car>(car => car.id == Guid.NewGuid()).Result;
        }
        public WhenCallingReadAndNoItemsMatchThePredicate()
        {
            // Given
            var testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingReadAndNoItemsMatchThePredicate));

            // When
            this.carsFromDatabase = testHarness.DataStore.Read <Car>(car => car.Make == "None").Result;
        }
        public WhenCallingDeleteSoftByIdOnAnItemThatDoesNotExist()
        {
            // Given
            var testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingDeleteSoftByIdOnAnItemThatDoesNotExist));

            //When
            this.result = testHarness.DataStore.DeleteSoftById <Car>(Guid.NewGuid()).Result;
            testHarness.DataStore.CommitChanges().Wait();
        }
        public WhenCallingDeleteSoftWhereAndNoItemsMatchThePredicate()
        {
            // Given
            var testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingDeleteSoftWhereAndNoItemsMatchThePredicate));

            //When
            this.result = testHarness.DataStore.DeleteSoftWhere <Car>(car => car.id == Guid.NewGuid()).Result;
            testHarness.DataStore.CommitChanges().Wait();
        }
        public WhenCallingUpdateGivenTheItemDoesNotExist()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingUpdateGivenTheItemDoesNotExist));

            //When
            this.result = this.testHarness.DataStore.Update(new Car()).Result;
            this.testHarness.DataStore.CommitChanges().Wait();
        }
Esempio n. 16
0
        public WhenCallingUpdateWhereGivenNoItemsExist()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingUpdateWhereGivenNoItemsExist));

            //When
            this.result = this.testHarness.DataStore.UpdateWhere <Car>(c => c.Make == "DoesNotExist", car => { }).Result;
            this.testHarness.DataStore.CommitChanges().Wait();
        }
        public WhenCallingUpdateByIdGivenTheItemDoesNotExist()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingUpdateByIdGivenTheItemDoesNotExist));

            var carId = Guid.NewGuid();

            //When
            this.result = this.testHarness.DataStore.UpdateById <Car>(carId, car => car.Make = "Whatever").Result;
            this.testHarness.DataStore.CommitChanges().Wait();
        }
        public WhenCallingCreateWithoutCommitting()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingCreateWithoutCommitting));

            var newCar = new Car
            {
                id   = Guid.NewGuid(),
                Make = "Volvo"
            };

            //When
            this.result = this.testHarness.DataStore.Create(newCar).Result;
        }
Esempio n. 19
0
        public WhenCallingUpdateOnAnItemThatNoLongerExistsInTheDatabase()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingUpdateOnAnItemThatNoLongerExistsInTheDatabase));

            var deletedCar = new Car
            {
                id   = Guid.NewGuid(),
                Make = "Volvo"
            };

            //When
            this.result = this.testHarness.DataStore.Update(deletedCar).Result;
            this.testHarness.DataStore.CommitChanges().Wait();
        }
Esempio n. 20
0
        public WhenCallingCreateWithTheReadOnlyFlagSetToTrue()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingCreateWithTheReadOnlyFlagSetToTrue));

            this.newCarId = Guid.NewGuid();
            var newCar = new Car
            {
                id   = this.newCarId,
                Make = "Volvo"
            };

            //When
            this.testHarness.DataStore.Create(newCar, true).Wait();
            this.testHarness.DataStore.CommitChanges().Wait();
        }
Esempio n. 21
0
        public WhenCallingUpdateWhereWithoutCommitting()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingUpdateWhereWithoutCommitting));

            this.carId = Guid.NewGuid();
            this.testHarness.AddToDatabase(
                new Car
            {
                id   = this.carId,
                Make = "Volvo"
            });

            //When
            this.testHarness.DataStore.UpdateWhere <Car>(car => car.id == this.carId, car => car.Make = "Ford").Wait();
        }
Esempio n. 22
0
        public WhenCallingDeleteHardById()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingDeleteHardById));

            this.carId = Guid.NewGuid();
            this.testHarness.AddToDatabase(
                new Car
            {
                id   = this.carId,
                Make = "Volvo"
            });

            //When
            this.result = this.testHarness.DataStore.DeleteHardById <Car>(this.carId).Result;
            this.testHarness.DataStore.CommitChanges().Wait();
        }
Esempio n. 23
0
        public WhenCallingExistsOnAnItemThatDoesNotExist()
        {
            // Given
            var testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingExistsOnAnItemThatDoesNotExist));

            var activeCarId       = Guid.NewGuid();
            var activeExistingCar = new Car
            {
                id   = activeCarId,
                Make = "Volvo"
            };

            testHarness.AddToDatabase(activeExistingCar);

            // When
            this.carExists = testHarness.DataStore.Exists(Guid.NewGuid()).Result;
        }
        public WhenCallingDeleteSoftWhere()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingDeleteSoftWhere));

            this.carId = Guid.NewGuid();
            this.testHarness.AddToDatabase(
                new Car
            {
                id   = this.carId,
                Make = "Volvo"
            });

            //When
            this.testHarness.DataStore.DeleteSoftWhere <Car>(car => car.id == this.carId).Wait();
            this.testHarness.DataStore.CommitChanges().Wait();
        }
        public WhenCallingDeleteHardWhereWithoutCommitting()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingDeleteHardWhereWithoutCommitting));

            var carId = Guid.NewGuid();

            this.testHarness.AddToDatabase(
                new Car
            {
                id   = carId,
                Make = "Volvo"
            });

            //When
            this.testHarness.DataStore.DeleteHardWhere <Car>(car => car.id == carId).Wait();
        }
        public WhenCallingUpdateWhereOnAnItemDeletedInThisSession()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingUpdateWhereOnAnItemDeletedInThisSession));

            this.carId = Guid.NewGuid();
            this.testHarness.AddToDatabase(
                new Car
            {
                id   = this.carId,
                Make = "Volvo"
            });
            this.testHarness.DataStore.DeleteHardById <Car>(this.carId).Wait();

            //When
            this.results = this.testHarness.DataStore.UpdateWhere <Car>(car => car.id == this.carId, car => car.Make = "Ford").Result;
        }
Esempio n. 27
0
        public WhenCallingExistsOnAnItemThatHasBeenDeletedInTheCurrentSession()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingExistsOnAnItemThatHasBeenDeletedInTheCurrentSession));

            this.activeCarId = Guid.NewGuid();
            var activeExistingCar = new Car
            {
                id   = this.activeCarId,
                Make = "Volvo"
            };

            this.testHarness.AddToDatabase(activeExistingCar);

            // When
            this.testHarness.DataStore.DeleteHardById <Car>(this.activeCarId).Wait();
        }
Esempio n. 28
0
        public WhenCallingUpdateById()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingUpdateById));

            this.carId = Guid.NewGuid();
            this.testHarness.AddToDatabase(
                new Car
            {
                id   = this.carId,
                Make = "Volvo"
            });

            //When
            this.testHarness.DataStore.UpdateById <Car>(this.carId, car => car.Make = "Ford").Wait();
            this.testHarness.DataStore.CommitChanges().Wait();
        }
Esempio n. 29
0
        public WhenCallingCommitMultipleTimesAfterACreateOperation()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingCommitMultipleTimesAfterACreateOperation));

            this.newCarId = Guid.NewGuid();
            var newCar = new Car
            {
                id   = this.newCarId,
                Make = "Volvo"
            };

            this.car = this.testHarness.DataStore.Create(newCar).Result;

            //When
            this.testHarness.DataStore.CommitChanges().Wait();
            this.testHarness.DataStore.CommitChanges().Wait();
        }
Esempio n. 30
0
        public WhenCallingReadCommittedWithATransformationToTheSameType()
        {
            // Given
            this.testHarness = TestHarnessFunctions.GetTestHarness(nameof(WhenCallingReadCommittedWithATransformationToTheSameType));

            var carId       = Guid.NewGuid();
            var existingCar = new Car
            {
                id     = carId,
                Active = false,
                Make   = "Volvo"
            };

            this.testHarness.AddToDatabase(existingCar);

            // When
            this.carFromDatabase = this.testHarness.DataStore.Advanced.ReadCommitted((IQueryable <Car> cars) => cars.Where(car => car.id == carId)).Result.Single();
        }