public void Test_Index() { Console.WriteLine (""); Console.WriteLine ("Preparing test"); Console.WriteLine (""); var data = GetGitDB (); var example1a = new SimpleEntity (); example1a.Text = "One"; data.Save (example1a); var example1b = new SimpleEntity (); example1b.Text = "One"; data.Save (example1b); var example2a = new SimpleEntity (); example2a.Text = "Two"; data.Save (example2a); var example2b = new SimpleEntity (); example2b.Text = "Two"; data.Save (example2b); var example3a = new SimpleEntity (); example3a.Text = "Three"; data.Save (example3a); var example3b = new SimpleEntity (); example3b.Text = "Three"; data.Save (example3b); var indexer = data.Indexer; indexer.IndexProperty (typeof(SimpleEntity), "Text"); var indexOne = indexer.GetIndex (typeof(SimpleEntity), "Text", "One"); Assert.AreEqual (2, indexOne.Length); Assert.AreEqual (example1a.Id, indexOne[0].Id); Assert.AreEqual (example1b.Id, indexOne[1].Id); var indexTwo = indexer.GetIndex (typeof(SimpleEntity), "Text", "Two"); Assert.AreEqual (2, indexTwo.Length); Assert.AreEqual (example2a.Id, indexTwo[0].Id); Assert.AreEqual (example2b.Id, indexTwo[1].Id); var indexThree = indexer.GetIndex (typeof(SimpleEntity), "Text", "Three"); Assert.AreEqual (2, indexThree.Length); Assert.AreEqual (example3a.Id, indexThree[0].Id); Assert.AreEqual (example3b.Id, indexThree[1].Id); }
public void Test_Save_EntityAlreadyExistsException() { // Create the entity var entity = new SimpleEntity (); var data = GetGitDB (); // Save the entity data.Save (entity); // Call the Save function again which should throw an exception data.Save(entity); }
public void BuildInstance() { SimpleEntity simpleEntity = new SimpleEntity(); OrderedDictionary values = new OrderedDictionary(3); values.Add("Id", 1); values.Add("Name", "name"); values.Add("Age", 10); TypeDescriptionHelper.BuildInstance(values, simpleEntity); Assert.AreEqual(1, simpleEntity.Id); Assert.AreEqual("name", simpleEntity.Name); Assert.AreEqual(10, simpleEntity.Age); }
public void AfterEntryMaterializedShouldOccur() { foreach (ODataFormat format in new ODataFormat[] {ODataFormat.Atom, ODataFormat.Json}) { var entity = new SimpleEntity() {ID = 1}; var odataEntry = CreateEntryWithMaterializerEntry(format, entity); MaterializedEntityArgs found = null; this.context.Configurations.ResponsePipeline.OnEntityMaterialized((MaterializedEntityArgs materializedEntryEventArgs) => found = materializedEntryEventArgs); this.context.Configurations.ResponsePipeline.FireEndEntryEvents(MaterializerEntry.GetEntry(odataEntry)); Assert.IsNotNull(found); found.Entity.Should().Be(entity); found.Entry.Should().Be(odataEntry); } }
public void Test_Save() { Console.WriteLine ("Preparing test"); // Create the entity var entity = new SimpleEntity (); Console.WriteLine ("Executing test"); var data = GetGitDB (); // Save the entity data.Save (entity); var filePath = new FileNamer (new DirectoryContext (Environment.CurrentDirectory)).CreateFilePath (entity.TypeName, entity.Id); Assert.IsTrue (File.Exists (filePath)); }
public void UnitOfWorkCommitTest() { var entity = new SimpleEntity { Name = "UnitTest" }; using (var unit = new UnitOfWork()) { Repository.Data.Save(entity); unit.Commit(); } Repository.Data.Cache.Clear(entity); ConversationHelper.ReOpen(); entity = Repository.Data.Get <SimpleEntity>(entity.Id); Assert.NotNull(entity); }
public void CompareDynamicObjectWithUnderlyingTypeNegative() { SimpleEntity x = new SimpleEntity(); dynamic dynamicX = x; dynamicX.Name = nameof(SimpleEntity); dynamicX.Id = typeof(SimpleEntity).GUID; SimpleEntity y = new SimpleEntity(); dynamic dynamicY = y; dynamicY.Name = nameof(SimpleEntity); dynamicY.Id = Guid.NewGuid(); CompareLogic comparer = new CompareLogic(); ComparisonResult result = comparer.Compare(dynamicX, dynamicY); Assert.False(result.AreEqual); }
public List <ItemTemplate> GetAllItems() { RestParameters urlParameters = new RestParameters() .AddParameters(RestParametersKeys.Token, user.Token); SimpleEntity simpleEntity = allItemsResource.HttpGetAsObject(urlParameters, null); List <string> list = new List <string>(simpleEntity.content .Split(new string[] { "\n", "\t", " \t" }, StringSplitOptions.None)); List <ItemTemplate> listItems = new List <ItemTemplate>(); for (int i = list.Count - 2; i > 0; i -= 2) { ItemTemplate template = new ItemTemplate(list[i], list[i - 1]); listItems.Add(template); LogManager.GetCurrentClassLogger() .Info("Index- " + template.Index); LogManager.GetCurrentClassLogger() .Info("Item- " + template.Item); } return(listItems); }
public async Task PostWithModelParam_WhenInvoked_ShouldAddEntityToRepository() { // Arrange SimpleEntity entityPassedToRepo = null; _MockEntityRepository .Setup(repo => repo.AddEntity(It.IsAny <SimpleEntity>())) .Callback <SimpleEntity>(paramSimpleEntity => entityPassedToRepo = paramSimpleEntity); var client = _Server.CreateClient(); // Act var postResponse = await client.PostAsync("/api/entities", new JsonContent(JToken.FromObject(new SimpleEntity("new 1")))); postResponse.EnsureSuccessStatusCode(); // Assert _MockEntityRepository.VerifyAll(); postResponse.StatusCode.Should().Be(HttpStatusCode.OK); entityPassedToRepo.Should().BeEquivalentTo(new SimpleEntity("new 1")); }
public void UpdateSimpleEntity() { // Arrange const int expectedId = 10; FakeDbContext dbContext = new FakeDbContext(); SimpleEntityRepository entityRepository = new SimpleEntityRepository(dbContext); SimpleEntity simpleEntity = new SimpleEntity { Id = expectedId }; // Act entityRepository.Update(simpleEntity); // Assert Assert.IsNotNull(entityRepository.DbContext); Assert.AreEqual(1, entityRepository.DbContext.ChangeTracker.Entries().Count()); Assert.AreEqual(EntityState.Modified, entityRepository.DbContext.FindEntity(expectedId).State); }
public void SetValueFromPath_ComplexValue_SetsValue() { //arrange var entity = new ComplexEntity { }; var value = new SimpleEntity { Foo = "I am foo", Bar = 12, Baz = "I am baz" }; // act PathHelper.SetValueFromPath(typeof(ComplexEntity), "/bar", entity, value, JsonPatchOperationType.add); //assert Assert.AreEqual("I am foo", entity.Bar.Foo); Assert.AreEqual(12, entity.Bar.Bar); Assert.AreEqual("I am baz", entity.Bar.Baz); }
public void AuditChanges_InsertSimpleEntity_AddsAuditLogWithCorrectEntityId() { using (DatabaseWrapper database = new DatabaseWrapper()) { //Arrange Guid userId = Guid.Parse("F37FEB8F-A364-47F6-86A5-02E191E8AF20"); SimpleEntity simple1 = new SimpleEntity("simple1"); database.TestContext.SimpleEntities.Add(simple1); database.TestContext.SetEntityId(); //Act database.TestContext.AuditChanges(userId); database.TestContext.SaveChanges(); //Assert //Audit Log stores correct entity Id Guid simple1Id = database.TestContext.SimpleEntities.Single(se => se.Data == "simple1").Id; Assert.NotNull(database.TestContext.AuditLogs.SingleOrDefault(al => al.RecordId == simple1Id)); } }
public void ShouldNotCallCreateOrUpdateIfDocumentEntityHaveDeleted() { var persistedEntity = SimpleEntity.CreateStandard(); unitOfWork.Attach(persistedEntity); var trancientEntity = SimpleEntity.CreateStandardWithoutRevision(); unitOfWork.AddNew(trancientEntity); unitOfWork.MarkAsRemoved(trancientEntity); unitOfWork.MarkAsRemoved(persistedEntity); var bulkUpdateUnitOfWorkMock = new Mock <IBulkUpdateBatch>(MockBehavior.Strict); bulkUpdateUnitOfWorkMock .Setup(u => u.Delete(It.IsAny <string>(), It.IsAny <string>())).Callback <string, string>((id, rev) => { }); //Should throw if methods other than Delete() have been called unitOfWork.ApplyChanges(bulkUpdateUnitOfWorkMock.Object); }
public void NestedUnitsWithInnerScopeRollbackAndCommitActionTest() { var entity = new SimpleEntity { Name = "UnitTest" }; var entity2 = new SimpleEntity { Name = "UnitTest2" }; using (var unit = new UnitOfWork()) { UnitOfWork.Current.PostCommitActions.Add(() => { }); UnitOfWork.Current.PostRollbackActions.Add(() => { }); Repository.Data.Save(entity); Assert.Equal(1, UnitOfWork.Current.PostCommitActions.Count); Assert.Equal(1, UnitOfWork.Current.PostRollbackActions.Count); using (var unit2 = new UnitOfWork(UnitOfWorkScopeType.New)) { UnitOfWork.Current.PostCommitActions.Add(() => { }); UnitOfWork.Current.PostRollbackActions.Add(() => { }); Repository.Data.Save(entity2); unit2.Rollback(); } Assert.Equal(1, UnitOfWork.Current.PostCommitActions.Count); Assert.Equal(1, UnitOfWork.Current.PostRollbackActions.Count); unit.Commit(); } Repository.Data.Cache.Clear(typeof(SimpleEntity)); ConversationHelper.ReOpen(); entity = Repository.Data.Get <SimpleEntity>(entity.Id); entity2 = Repository.Data.Get <SimpleEntity>(entity2.Id); Assert.NotNull(entity); Assert.Null(entity2); }
public void ShouldDeleteDocumentOnlyOnce() { var entity = SimpleEntity.CreateStandard(); unitOfWork.MarkAsRemoved(entity); unitOfWork.MarkAsRemoved(entity); int callTimes = 0; var bulkUpdateUnitOfWorkMock = new Mock <IBulkUpdateBatch>(MockBehavior.Strict); bulkUpdateUnitOfWorkMock .Setup(u => u.Delete(It.IsAny <string>(), It.IsAny <string>())) .Callback <string, string>( (id, rev) => { callTimes++; }); unitOfWork.ApplyChanges(bulkUpdateUnitOfWorkMock.Object); Assert.Equal(1, callTimes); }
public void ShouldDeleteEntitiesDocument() { unitOfWork.MarkAsRemoved(SimpleEntity.CreateStandard()); string deletedDocId = null; string deletedDocRevision = null; var bulkUpdateUnitOfWorkMock = new Mock <IBulkUpdateBatch>(MockBehavior.Strict); bulkUpdateUnitOfWorkMock .Setup(u => u.Delete(It.IsAny <string>(), It.IsAny <string>())) .Callback <string, string>( (id, rev) => { deletedDocId = id; deletedDocRevision = rev; }); unitOfWork.ApplyChanges(bulkUpdateUnitOfWorkMock.Object); Assert.Equal(SimpleEntity.StandardDocId, deletedDocId); Assert.Equal(SimpleEntity.StandardRevision, deletedDocRevision); }
public void Delete_LabelIsNull_NoLabelComment() { using (var connection = new DbConnectionStub()) using (var context = new DataContext(connection) { StatementsLabel = null }) { var table = context.GetTable <SimpleEntity>(); var entity = new SimpleEntity(); table.Attach(entity); table.DeleteOnSubmit(entity); var commandText = context.GetChangeText(); var expectedFirstPart = "DELETE FROM [SimpleTable]" + Environment.NewLine; Assert.IsTrue(commandText.StartsWith(expectedFirstPart), commandText); } }
public void TryToAutoMergeIfNeeded() { var item = new SimpleEntity { Name = "PageType #1" }; Repository.Data.Save(item); ConversationHelper.ReOpen(); item = Repository.Data.Get <SimpleEntity>(item.Id); item.Name += ".2"; Repository.Data.Save(item); ConversationHelper.ReOpen(); Repository.Data.Get <SimpleEntity>(item.Id); item.Name += ".3"; Repository.Data.Save(item); }
public static void Update(SimpleEntity app) { DAL.tblAuthorizationSimpleEntity dataItem = DAL.CurrDBContext.Get().tblAuthorizationSimpleEntity. Where(x => x.RoleId == app.RoleId && x.EntityId == app.EntityId).Single(); dataItem.AllowMethodReadWithFilters = app.AllowMethodReadWithFilters; dataItem.AllowMethodCreateOne = app.AllowMethodCreateOne; dataItem.AllowMethodReadOne = app.AllowMethodReadOne; dataItem.AllowMethodUpdateOne = app.AllowMethodUpdateOne; dataItem.AllowMethodDeleteOne = app.AllowMethodDeleteOne; dataItem.AllowMethodCreateMultiple = app.AllowMethodCreateMultiple; dataItem.AllowMethodReadMultiple = app.AllowMethodUpdateMultiple; dataItem.AllowMethodUpdateMultiple = app.AllowMethodUpdateMultiple; dataItem.AllowMethodDeleteMultiple = app.AllowMethodDeleteMultiple; dataItem.AllowMethodCreateLink = app.AllowMethodCreateLink; dataItem.AllowMethodReadLink = app.AllowMethodReadLink; dataItem.AllowMethodUpdateLink = app.AllowMethodUpdateLink; dataItem.AllowMethodDeleteLink = app.AllowMethodDeleteLink; DAL.CurrDBContext.Get().SaveChanges(); }
public void AuditChanges_InsertSimpleEntity_AddsAuditLogForCorrectTable() { using (DatabaseWrapper database = new DatabaseWrapper()) { //Arrange Guid userId = Guid.Parse("F37FEB8F-A364-47F6-86A5-02E191E8AF20"); SimpleEntity simple1 = new SimpleEntity("simple1"); database.TestContext.SimpleEntities.Add(simple1); database.TestContext.SetEntityId(); //Act database.TestContext.AuditChanges(userId); database.TestContext.SaveChanges(); //Assert //Audit Log stores correct table Guid simple1Id = database.TestContext.SimpleEntities.Single(se => se.Data == "simple1").Id; Assert.Matches("\\[Test\\]\\.\\[SimpleEntity\\]", database.TestContext.AuditLogs.Single(al => al.RecordId == simple1Id).TableName); } }
public void InsertMultipleSimpleEntities() { // Arrange FakeDbContext dbContext = new FakeDbContext(); SimpleEntityRepository entityRepository = new SimpleEntityRepository(dbContext); SimpleEntity simpleEntity1 = new SimpleEntity { SomeProperty = "Some property 1" }; SimpleEntity simpleEntity2 = new SimpleEntity { SomeProperty = "Some property 2" }; // Act entityRepository.Insert(simpleEntity1); entityRepository.Insert(simpleEntity2); // Assert Assert.IsNotNull(entityRepository.DbContext); Assert.AreEqual(2, entityRepository.DbContext.ChangeTracker.Entries().Count()); entityRepository.DbContext.ChangeTracker.Entries().ToList().ForEach(entry => Assert.AreEqual(EntityState.Added, entry.State)); }
/// <summary> /// Tests that when we query for an existing entity, it is returned correctly /// </summary> //[Test] public void GetExistingSingleEntity() { // Arrange const int expectedId = 10; // Create a repository with a mock dbset, so any queries will be done against the list rather than DB SimpleEntityRepository entityRepository = CreateSimpleEntityRepositoryWithMockDbSet( new List <SimpleEntity> { new SimpleEntity { Id = expectedId } } ); // Act SimpleEntity entity = entityRepository.GetSingle(se => se.Id == expectedId); // Assert Assert.IsNotNull(entity); Assert.AreEqual(expectedId, entity.Id); }
public void AuditChanges_InsertSimpleEntity_AddsAuditLogWithExpectedJson() { using (DatabaseWrapper database = new DatabaseWrapper()) { //Arrange Guid userId = Guid.Parse("F37FEB8F-A364-47F6-86A5-02E191E8AF20"); SimpleEntity simple1 = new SimpleEntity("simple1"); database.TestContext.SimpleEntities.Add(simple1); database.TestContext.SetEntityId(); //Act database.TestContext.AuditChanges(userId); database.TestContext.SaveChanges(); //Assert //Audit Log stores correct Json Guid simple1Id = database.TestContext.SimpleEntities.Single(se => se.Data == "simple1").Id; String expectedJson = "{\\\"Id\\\":\\\"" + simple1Id + "\\\",\\\"Data\\\":\\\"simple1\\\",\\\"RowVersion\\\":null}"; Assert.Matches(expectedJson, database.TestContext.AuditLogs.Single(al => al.RecordId == simple1Id).NewValue); } }
public async void AuditChanges_InsertEntityWithChildrenAndUpdateChildren_AddsAuditLogWithExpectedOriginalForeignKeyJson() { using (DatabaseWrapper database = new DatabaseWrapper()) { //Arrange //Add initial entities Guid userId = Guid.Parse("F37FEB8F-A364-47F6-86A5-02E191E8AF20"); SimpleEntity sA = new SimpleEntity("Simple A"); SimpleEntity sB = new SimpleEntity("Simple B"); database.TestContext.SimpleEntities.AddRange(new List <SimpleEntity> { sA, sB }); EntityWithChildren ewc = new EntityWithChildren(sA, sB); database.TestContext.ParentEntities.Add(ewc); database.TestContext.SetEntityId(); database.TestContext.AuditChanges(userId); await database.TestContext.SaveChangesAsync(); // Update exisiting EntityWithChildren with new child entity SimpleEntity sBv2 = new SimpleEntity("Simple B Version 2"); database.TestContext.SimpleEntities.Add(sBv2); ewc.UpdateSimpleEntityB(sBv2); database.TestContext.SetEntityId(); //Act database.TestContext.AuditChanges(userId); await database.TestContext.SaveChangesAsync(); //Assert //Audit Log stores correct original json, with foreign keys Guid ewcId = database.TestContext.ParentEntities.Single().Id; Guid sBId = database.TestContext.SimpleEntities.Single(se => se.Data == "Simple B").Id; String expectedOriginalJson = "{\\\"Id\\\":\\\"" + ewcId + "\\\",\\\"SimpleEntityBId\\\":\\\"" + sBId + "\\\",\\\"RowVersion\\\":.*}"; List <AuditLog> orderedLogs = database.TestContext.AuditLogs.OrderBy(a => a.EventDate).ToList(); Assert.Matches(expectedOriginalJson, orderedLogs.Last(al => al.RecordId == ewcId).OriginalValue); } }
public void ClearCacheForEntityTypeTest() { var item1 = new SimpleCacheEntity { Name = "Query Cache Test #1" }; var item2 = new SimpleCacheEntity { Name = "Query Cache Test #2" }; var item3 = new SimpleEntity { Name = "Query Cache Test #3" }; Repository.Data.Save(item1); Repository.Data.Save(item2); Repository.Data.Save(item3); var cachedEntity1 = GetCachedObjectDirectly(item1.Id, item1.GetType()); Assert.NotNull(cachedEntity1); var cachedEntity2 = GetCachedObjectDirectly(item2.Id, item2.GetType()); Assert.NotNull(cachedEntity2); var cachedEntity3 = GetCachedObjectDirectly(item3.Id, item3.GetType()); Assert.NotNull(cachedEntity3); Repository.Data.Cache.Clear(typeof(SimpleCacheEntity)); cachedEntity1 = GetCachedObjectDirectly(item1.Id, item1.GetType()); Assert.Null(cachedEntity1); cachedEntity2 = GetCachedObjectDirectly(item2.Id, item2.GetType()); Assert.Null(cachedEntity2); cachedEntity3 = GetCachedObjectDirectly(item3.Id, item3.GetType()); Assert.NotNull(cachedEntity3); }
public void NestedUnitsWithNewInnerScopeException() { var entity = new SimpleEntity { Name = "UnitTest" }; var entity2 = new SimpleEntity { Name = "UnitTest" }; using (var unit = new UnitOfWork()) { Repository.Data.Save(entity); using (var unit2 = new UnitOfWork(UnitOfWorkScopeType.New)) { using (var unit3 = new UnitOfWork()) { Repository.Data.Save(entity2); Assert.Throws <UnitOfWorkException>(() => unit3.Rollback()); // will throw exception because this is not the owner of the UOW } // user will not come to this point and try to commit transaction // else it should throw exception Assert.Throws <UnitOfWorkException>(() => unit2.Commit()); } // user can commit the outer UOW if unit2-UOW is inside an try/catch unit.Commit(); } Repository.Data.Cache.Clear(typeof(SimpleEntity)); ConversationHelper.ReOpen(); entity = Repository.Data.Get <SimpleEntity>(entity.Id); entity2 = Repository.Data.Get <SimpleEntity>(entity2.Id); Assert.NotNull(entity); Assert.Null(entity2); }
public List <IUser> GetAllAdmins(IUser newAdmin) { RestParameters urlParameters = new RestParameters() .AddParameters(RestParametersKeys.Token, newAdmin.Token); SimpleEntity simpleEntity = adminsResource.HttpGetAsObject(urlParameters, null); string[] contentArray = simpleEntity.content.Split(' '); int counter = 0; foreach (string i in contentArray) { contentArray[counter] = new String(i.Where(Char.IsLetter).ToArray()); counter++; } List <IUser> returnedUsers = new List <IUser> { }; foreach (string i in contentArray) { returnedUsers.Add(new User(i)); } return(returnedUsers); }
public void ShouldUpdatePersistedDocumens() { var entity = SimpleEntity.CreateStandard(); entity.Age = 24; unitOfWork.Attach(entity); Document savedDoc = null; var bulkUpdateUnitOfWorkMock = new Mock <IBulkUpdateBatch>(MockBehavior.Strict); bulkUpdateUnitOfWorkMock .Setup(u => u.Update(It.IsAny <Document>())) .Callback <Document>(d => { savedDoc = d; }); unitOfWork.ApplyChanges(bulkUpdateUnitOfWorkMock.Object); Assert.NotNull(savedDoc); var expectedDoc = new { _id = SimpleEntity.StandardDocId, _rev = SimpleEntity.StandardRevision, type = SimpleEntity.DocType, age = 24 }.ToDocument(); Assert.Equal(expectedDoc, savedDoc); }
public void NestedUnitsWithInnerScopeWithoutException() { var entity = new SimpleEntity { Name = "UnitTest" }; var entity2 = new SimpleEntity { Name = "UnitTest2" }; using (var unit = new UnitOfWork()) { Repository.Data.Save(entity); using (var unit2 = new UnitOfWork(UnitOfWorkScopeType.New)) { Repository.Data.Save(entity2); unit2.Rollback(); // will not throw exception because this is own transaction } // user can commit the outer UOW unit.Commit(); } }
public void ShouldBeEmptyAfterUpdatingRevision() { var entity = SimpleEntity.CreateStandard(); unitOfWork.Attach(entity); unitOfWork.MarkAsRemoved(entity); unitOfWork.AddNew(EntityWithoutRevision.CreateStandard()); var bulkUpdateBatchA = CreateBulkUpdateBatch(); unitOfWork.ApplyChanges(bulkUpdateBatchA); // Starting saving changes unitOfWork.UpdateRevisions( // Returned from server after changes have been saved new [] { new DocumentInfo(SimpleEntity.StandardDocId, "2-cc2c5ab22cfa4a0faad27a0cb9ca7968"), new DocumentInfo(EntityWithoutRevision.StandardDocId, EntityWithoutRevision.StandardRevision) } ); var bulkUpdateBatchB = CreateBulkUpdateBatch(); Assert.False(unitOfWork.ApplyChanges(bulkUpdateBatchB)); Assert.True(bulkUpdateBatchB.IsEmpty); }
public void UnitOfWorkRollBackAfterCommitTest() { var entity = new SimpleEntity { Name = "UnitTest" }; using (var unit = new UnitOfWork()) { Repository.Data.Save(entity); //Some external method UnitOfWork.Current.Commit(); Assert.Throws <UnitOfWorkException>(() => unit.Rollback()); } Repository.Data.Cache.Clear(entity); ConversationHelper.ReOpen(); entity = Repository.Data.Get <SimpleEntity>(entity.Id); Assert.NotNull(entity); }
public void EventHandlingExceptionTest() { bool exceptionWasThrown; var entity = new SimpleEntity { Name = "EventHandlingExceptionTester" }; try { SimpleEntity entity1 = entity; var exception = Assert.Throws( typeof(EventHandlingException <SimpleEntity, ValidateEvent>), () => Repository.Data.Save(entity1)); throw exception; } catch (EventHandlingException <SimpleEntity, ValidateEvent> ex) { exceptionWasThrown = true; Assert.Equal(typeof(SimpleEntity), ex.EntityType); Assert.Equal(typeof(ValidateEvent), ex.EventType); Assert.True(ex.EventArgs.Entity != null); Console.WriteLine( string.Format("An exception was thrown during handling the '{0}' event for '{1}' entity with Id={2}.", ex.EventType.Name, ex.EntityType.Name, ex.EventArgs.Entity.Id)); Console.WriteLine("Message:"); Console.WriteLine(ex.Message); } Assert.True(exceptionWasThrown); Repository.Data.Cache.Clear(); entity = Repository.Data.Get <SimpleEntity>(entity.Id); Assert.Null(entity); }
public void Test_IndexAndRead() { Console.WriteLine (""); Console.WriteLine ("Preparing test"); Console.WriteLine (""); var data = GetGitDB (); var example1a = new SimpleEntity (); example1a.Text = "One"; data.Save (example1a); var example2a = new SimpleEntity (); example2a.Text = "Two"; data.Save (example2a); var example3a = new SimpleEntity (); example3a.Text = "Three"; data.Save (example3a); var indexer = data.Indexer; indexer.IndexProperty (typeof(SimpleEntity), "Text"); var foundEntity1 = indexer.Read (typeof(SimpleEntity), "Text", "One"); Assert.AreEqual (example1a.Id, foundEntity1.Id); var foundEntity2 = indexer.Read (typeof(SimpleEntity), "Text", "Two"); Assert.AreEqual (example2a.Id, foundEntity2.Id); var foundEntity3 = indexer.Read (typeof(SimpleEntity), "Text", "Three"); Assert.AreEqual (example3a.Id, foundEntity3.Id); }
public void Update_LabelIsNotNull_LabelAddedToSqlTextOnce() { using (var connection = new DbConnectionStub()) using (var context = new DataContext(connection) { StatementsLabel = Label }) { var table = context.GetTable <SimpleEntity>(); var entity = new SimpleEntity(); table.Attach(entity); entity.X = 10; var commandText = context.GetChangeText(); var expectedFirstPart = "UPDATE " + Environment.NewLine + $"{LabelWithCommentSymbols}" + Environment.NewLine; Assert.IsTrue(commandText.StartsWith(expectedFirstPart), commandText); AssertThatLabelPresentedInCommandTextOnce(commandText); } }
// TODO: Use a value generator to handle this automatically private void SetPartitionId(SimpleEntity entity, CrossStoreContext context) { var property = context.Model.GetEntityType(entity.GetType()).GetProperty(SimpleEntity.ShadowPartitionIdName); context.Entry(entity).GetService()[property] = "Partition"; }
// TODO: Use a value generator to handle this automatically private void SetPartitionId(SimpleEntity entity, CrossStoreContext context) { var property = context.Model.FindEntityType(entity.GetType()).FindProperty(SimpleEntity.ShadowPartitionIdName); context.Entry(entity).GetInfrastructure()[property] = "Partition"; }