public void AddRecord(string visitorName, DateTime timeOfVisit) { FileInfo fileInfo = new DirectoryInfo(_directoryName) .GetFiles() .OrderByDescending(x => x.LastWriteTime) .First(); FileContent file = _persister.ReadFile(fileInfo.Name); FileAction action = _auditManager.AddRecord(file, visitorName, timeOfVisit); _persister.ApplyChange(action); }
public void AddRecord_adds_a_record_to_a_new_file_if_overflowed() { var sut = new AuditManager(1); FileContent fileContent = new FileContent("Audit_1.txt", new[] { "1;Peter Peterson;2020-04-06T16:30:00", }); FileAction action = sut.AddRecord(fileContent, "Renan Romero", new DateTime(2021, 4, 7, 9, 5, 0)); Assert.Equal("Audit_2.txt", action.FileName); Assert.Equal(ActionType.Create, action.Type); Assert.Equal(new[] { "1;Renan Romero;2021-04-07T09:05:00" }, action.Content); }
public void AddRecord_adds_a_record_to_a_new_file_if_overflowed() { var manager = new AuditManager(1); var file = new FileContent("Audit_1.txt", new[] { "1;Németh Dávid;2016-06-09T08:37:00" }); FileAction action = manager.AddRecord(file, "Sasha Grey", new System.DateTime(2016, 6, 9, 08, 41, 0)); Assert.Equal(ActionType.Create, action.Type); Assert.Equal("Audit_2.txt", action.FileName); Assert.Equal(new[] { "1;Sasha Grey;2016-06-09T08:41:00" }, action.Content); }
public void AddRecord_When_Given_A_New_Entry_And_The_Current_File_Is_Overflowed_Should_Add_It_To_A_New_File() { var manager = new AuditManager(1); var file = new FileContent("Audit_1.txt", new[] { "1;fernando;2020-04-16T08:32:14" }); var action = manager.AddRecord(file, "flavio", new DateTime(2020, 4, 16, 9, 0, 0)); Assert.Equal(EActionType.Create, action.Type); Assert.Equal("Audit_2.txt", action.FileName); Assert.Equal(new[] { "1;flavio;2020-04-16T09:00:00" }, action.Content); }
public void AddRecord_adds_a_record_to_an_existing_file_if_not_overflowed() { var manager = new AuditManager(10); var file = new FileContent("Audit_1.txt", new[] { "1;Peter Peterson;2016-04-06T16:30:00" }); FileAction action = manager.AddRecord(file, "Jane Doe", new DateTime(2016, 4, 6, 17, 0, 0)); Assert.Equal(ActionType.Update, action.Type); Assert.Equal("Audit_1.txt", action.FileName); Assert.Equal(new[] { "1;Peter Peterson;2016-04-06T16:30:00", "2;Jane Doe;2016-04-06T17:00:00" }, action.Content); }
public void AddRecord_When_Given_A_New_Entry_Should_Add_It() { var manager = new AuditManager(10); var file = new FileContent("Audit_1.txt", new[] { "1;fernando;2020-04-16T08:32:14" }); var action = manager.AddRecord(file, "flavio", new DateTime(2020, 4, 16, 9, 0, 0)); Assert.Equal(EActionType.Update, action.Type); Assert.Equal("Audit_1.txt", action.FileName); Assert.Equal(new[] { "1;fernando;2020-04-16T08:32:14", "2;flavio;2020-04-16T09:00:00" }, action.Content); }
public void AddRecord_adds_a_record_to_a_new_file_if_overflowed() { var manager = new AuditManager(3); var file = new FileContent("Audit_1.txt", new[] { "1;Peter Peterson;2016-04-06T16:30:00", "2;Jane Doe;2016-04-06T16:40:00", "3;Jack Rich;2016-04-06T17:00:00" }); FileAction action = manager.AddRecord(file, "Tom Tomson", new DateTime(2016, 4, 6, 17, 30, 0)); Assert.Equal(ActionType.Create, action.Type); Assert.Equal("Audit_2.txt", action.FileName); Assert.Equal(new[] { "1;Tom Tomson;2016-04-06T17:30:00" }, action.Content); }
public static void Main(string[] args) { var manager = new AuditManager(5); manager.AddRecord("Audit_1.txt", "flavio", DateTime.Now); }