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

            Assert.Throws <ArgumentException>(() =>
            {
                collection.New(model);
                collection.New(model);
            });
        }
Esempio n. 2
0
        public void Persist_TwoAdded_Success()
        {
            var trackedCollection = new TrackedModelCollection <BlankAggregate>();
            var model1            = new BlankAggregate();
            var model2            = new BlankAggregate();

            trackedCollection.New(model1);
            trackedCollection.New(model2);

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

            Assert.AreEqual(2, changes.Count());
            Assert.IsTrue(changes.All(c => c.ModelType == WriteModelType.InsertOne), "Expected all changes to be inserts");
        }
        public void Add_Null_Failure()
        {
            var collection = new TrackedModelCollection <BlankAggregate>();

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

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

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

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

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

            Assert.AreEqual(model, collection.OfState(TrackedModelState.New).SingleOrDefault()?.Model);
        }
        public void Remove_Added_Success()
        {
            var collection = new TrackedModelCollection <BlankAggregate>();
            var model      = new BlankAggregate();

            collection.New(model);

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

            CollectionAssert.DoesNotContain(collection.Select(m => m.Model), model);
        }