public void Existing_SameModelTwice_Failure()
        {
            var collection = new TrackedModelCollection <BlankAggregate>();
            var model      = new BlankAggregate();

            Assert.Throws <ArgumentException>(() =>
            {
                collection.Existing(model);
                collection.Existing(model);
            });
        }
Exemple #2
0
        public void Persist_NoneRemoved_DatabaseNotCalled()
        {
            var trackedCollection = new TrackedModelCollection <GuidAggregate>();
            var model1            = new GuidAggregate();
            var model2            = new GuidAggregate();

            trackedCollection.Existing(model1);
            trackedCollection.Existing(model2);

            var persister = new TrackedModelPersister <GuidAggregate>();
            var changes   = persister.GetChangesForWrite(trackedCollection).ToArray();

            Assert.AreEqual(0, changes.Count());
        }
Exemple #3
0
        public void Persist_SingleRemoved_Success()
        {
            var trackedCollection = new TrackedModelCollection <GuidAggregate>();
            var model1            = new GuidAggregate();
            var model2            = new GuidAggregate();

            trackedCollection.Existing(model1);
            trackedCollection.Existing(model2);
            trackedCollection.Remove(model1);

            var persister = new TrackedModelPersister <GuidAggregate>();
            var changes   = persister.GetChangesForWrite(trackedCollection).ToArray();

            Assert.AreEqual(1, changes.Count());

            AssertModelsDeleted(changes, model1.Id);
        }
Exemple #4
0
        public void Persist_TwoUpdated_Success()
        {
            var trackedCollection = new TrackedModelCollection <FlatAggregate>();
            var model1            = new FlatAggregate();
            var model2            = new FlatAggregate();

            trackedCollection.Existing(model1);
            trackedCollection.Existing(model2);
            model1.Name = "Jane Doe";
            model2.Name = "Bob Sinclair";

            var persister = new TrackedModelPersister <FlatAggregate>();
            var changes   = persister.GetChangesForWrite(trackedCollection).ToArray();

            Assert.AreEqual(2, changes.Count());
            AssertModelsUpdated(changes, model1.Id, model2.Id);
        }
        public void Existing_Null_Failure()
        {
            var collection = new TrackedModelCollection <BlankAggregate>();

            Assert.Throws <ArgumentNullException>(() =>
            {
                collection.Existing(null);
            });
        }
        public void Existing_Multiple_Success()
        {
            var collection = new TrackedModelCollection <BlankAggregate>();
            var model1     = new BlankAggregate();
            var model2     = new BlankAggregate();

            Assert.DoesNotThrow(() =>
            {
                collection.Existing(model1);
                collection.Existing(model2);
            });

            var addedModels = collection.OfState(TrackedModelState.Existing).Select(m => m.Model).ToList();

            Assert.AreEqual(2, addedModels.Count());
            Assert.Contains(model1, addedModels);
            Assert.Contains(model2, addedModels);
        }
        public void Remove_MultipleExisting_Success()
        {
            var collection = new TrackedModelCollection <BlankAggregate>();
            var model1     = new BlankAggregate();
            var model2     = new BlankAggregate();

            collection.Existing(model1);
            collection.Existing(model2);

            Assert.DoesNotThrow(() =>
            {
                collection.Remove(model1);
                collection.Remove(model2);
            });

            var removedModels = collection.OfState(TrackedModelState.Removed).Select(m => m.Model).ToList();

            CollectionAssert.Contains(removedModels, model1);
            CollectionAssert.Contains(removedModels, model2);
        }
        public void Existing_Single_Success()
        {
            var collection = new TrackedModelCollection <BlankAggregate>();
            var model      = new BlankAggregate();

            Assert.DoesNotThrow(() =>
            {
                collection.Existing(model);
            });

            Assert.AreEqual(model, collection.OfState(TrackedModelState.Existing).SingleOrDefault()?.Model);
        }
Exemple #9
0
        public void Persist_SingleUpdated_Success()
        {
            var trackedCollection = new TrackedModelCollection <FlatAggregate>();
            var model             = new FlatAggregate();

            trackedCollection.Existing(model);
            model.Name = "Jane Doe";

            var persister = new TrackedModelPersister <FlatAggregate>();
            var changes   = persister.GetChangesForWrite(trackedCollection).ToArray();

            Assert.AreEqual(1, changes.Count());
            AssertModelsUpdated(changes, model.Id);
        }
        public void Remove_SingleExisting_Success()
        {
            var collection = new TrackedModelCollection <BlankAggregate>();
            var model      = new BlankAggregate();

            collection.Existing(model);

            Assert.DoesNotThrow(() =>
            {
                collection.Remove(model);
            });

            CollectionAssert.Contains(collection.OfState(TrackedModelState.Removed).Select(m => m.Model), model);
        }
Exemple #11
0
        private static SubEntityAsDeltaAggregate GetNullTrackedSubEntityAggregate(
            out TrackedModel <SubEntityAsDeltaAggregate> trackedModel)
        {
            var model = new SubEntityAsDeltaAggregate
            {
                NonDeltaValue = null,
                DeltaValue    = null
            };

            var trackingCollection = new TrackedModelCollection <SubEntityAsDeltaAggregate>();

            trackingCollection.Existing(model);
            trackedModel = trackingCollection.Single();
            return(model);
        }
Exemple #12
0
        private static FlatAggregate GetTrackedFlatAggregate(out TrackedModel <FlatAggregate> trackedModel)
        {
            var model = new FlatAggregate()
            {
                Id          = Guid.NewGuid(),
                Name        = "Bob Smith",
                Age         = 20,
                DateOfBirth = new DateTime(2000, 01, 01)
            };
            var trackingCollection = new TrackedModelCollection <FlatAggregate>();

            trackingCollection.Existing(model);
            trackedModel = trackingCollection.Single();
            return(model);
        }
Exemple #13
0
        private static IncrementNumeralsAggregate GetTrackedIncrementNumeralsAggregate(
            out TrackedModel <IncrementNumeralsAggregate> trackedModel)
        {
            var model = new IncrementNumeralsAggregate
            {
                Name    = "Name",
                Integer = 5,
                Long    = 120567,
                Decimal = 65.3M,
                Double  = 67384.8956
            };

            var trackingCollection = new TrackedModelCollection <IncrementNumeralsAggregate>();

            trackingCollection.Existing(model);
            trackedModel = trackingCollection.Single();
            return(model);
        }