public void advisoryBuilder_generateAdvisory_for_non_transient_and_changed_entity() { var expectedAction = ProposedActions.Update; var entity = new Object(); var entityState = EntityTrackingStates.HasBackwardChanges; var c1 = A.Fake <IChange>(); A.CallTo(() => c1.GetChangedEntities()).Returns(new Object[] { entity }); A.CallTo(() => c1.GetAdvisedAction(entity)).Returns(ProposedActions.Update | ProposedActions.Create); var c2 = A.Fake <IChange>(); A.CallTo(() => c2.GetChangedEntities()).Returns(new Object[] { entity }); A.CallTo(() => c2.GetAdvisedAction(entity)).Returns(ProposedActions.Update | ProposedActions.Create); var cSet = new ChangeSet(new IChange[] { c1, c2 }); var svc = A.Fake <IChangeTrackingService>(); A.CallTo(() => svc.GetEntityState(entity)).Returns(entityState); A.CallTo(() => svc.GetEntities(EntityTrackingStates.IsTransient, true)).Returns(new object[0]); var actual = new AdvisoryBuilder(new ChangeSetDistinctVisitor()); IAdvisory advisory = actual.GenerateAdvisory(svc, cSet); advisory.Should().Not.Be.Null(); advisory.Count.Should().Be.EqualTo(1); advisory.First().Action.Should().Be.EqualTo(expectedAction); advisory.First().Target.Should().Be.EqualTo(entity); }
public void advisoryBuilder_generateAdvisory_for_strict_isTransient_entity() { var expectedAction = ProposedActions.Create; var entity = new Object(); var entityState = EntityTrackingStates.IsTransient; var cSet = new ChangeSet(new IChange[0]); var svc = A.Fake <IChangeTrackingService>(); A.CallTo(() => svc.GetEntityState(entity)).Returns(entityState); A.CallTo(() => svc.GetEntities(EntityTrackingStates.IsTransient, true)).Returns(new object[] { entity }); var actual = new AdvisoryBuilder(new ChangeSetDistinctVisitor()); IAdvisory advisory = actual.GenerateAdvisory(svc, cSet); advisory.Should().Not.Be.Null(); advisory.Count.Should().Be.EqualTo(1); advisory.First().Action.Should().Be.EqualTo(expectedAction); advisory.First().Target.Should().Be.EqualTo(entity); }
public void service_getAdvisory_generate_valid_advisory_with_more_changes_applied_to_the_same_entity() { ProposedActions expected = ProposedActions.Delete; ChangeTrackingService svc = new ChangeTrackingService(); PersonCollection list = new PersonCollection(svc); list.Add(new Person(null, false)); //First IChange list.RemoveAt(0); //Second IChange IAdvisory advisory = svc.GetAdvisory(); IAdvisedAction action = advisory.First(); ProposedActions actual = action.Action; Assert.AreEqual <ProposedActions>(expected, actual); }