public override void SetUp () { base.SetUp (); RunAsync (async delegate { workspace = await DataStore.PutAsync (new WorkspaceData () { Name = "Test", }); user = await DataStore.PutAsync (new UserData () { Name = "John Doe", TrackingMode = TrackingMode.StartNew, DefaultWorkspaceId = workspace.Id, }); await SetUpFakeUser (user.Id); var activeManager = new ActiveTimeEntryManager (); await Util.AwaitPredicate (() => activeManager.ActiveTimeEntry != null); ServiceContainer.Register<ExperimentManager> (new ExperimentManager ()); ServiceContainer.Register<ISyncManager> (Mock.Of<ISyncManager> (mgr => !mgr.IsRunning)); ServiceContainer.Register<ActiveTimeEntryManager> (activeManager); ServiceContainer.Register<ITracker> (() => new FakeTracker ()); }); }
public WorkspaceData Import (IDataStoreContext ctx, WorkspaceJson json, Guid? localIdHint = null, WorkspaceData mergeBase = null) { var data = GetByRemoteId<WorkspaceData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new WorkspaceMerger (mergeBase) : null; if (merger != null && data != null) merger.Add (new WorkspaceData (data)); if (json.DeletedAt.HasValue) { if (data != null) { ctx.Delete (data); data = null; } } else if (merger != null || ShouldOverwrite (data, json)) { data = data ?? new WorkspaceData (); ImportJson (data, json); if (merger != null) { merger.Add (data); data = merger.Result; } data = ctx.Put (data); } return data; }
public WorkspaceData (WorkspaceData other) : base (other) { Name = other.Name; IsPremium = other.IsPremium; DefaultRate = other.DefaultRate; DefaultCurrency = other.DefaultCurrency; ProjectCreationPrivileges = other.ProjectCreationPrivileges; BillableRatesVisibility = other.BillableRatesVisibility; RoundingMode = other.RoundingMode; RoundingPercision = other.RoundingPercision; LogoUrl = other.LogoUrl; }
public WorkspaceData(WorkspaceData other) : base(other) { Name = other.Name; IsPremium = other.IsPremium; DefaultRate = other.DefaultRate; DefaultCurrency = other.DefaultCurrency; ProjectCreationPrivileges = other.ProjectCreationPrivileges; BillableRatesVisibility = other.BillableRatesVisibility; RoundingMode = other.RoundingMode; RoundingPercision = other.RoundingPercision; LogoUrl = other.LogoUrl; }
private static void ImportJson (WorkspaceData data, WorkspaceJson json) { data.Name = json.Name; data.IsPremium = json.IsPremium; data.DefaultRate = json.DefaultRate; data.DefaultCurrency = json.DefaultCurrency; data.ProjectCreationPrivileges = json.OnlyAdminsMayCreateProjects ? AccessLevel.Admin : AccessLevel.Regular; data.BillableRatesVisibility = json.OnlyAdminsSeeBillableRates ? AccessLevel.Admin : AccessLevel.Regular; data.RoundingMode = json.RoundingMode; data.RoundingPercision = json.RoundingPercision; data.LogoUrl = json.LogoUrl; ImportCommonJson (data, json); }
public WorkspaceJson Export (IDataStoreContext ctx, WorkspaceData data) { return new WorkspaceJson () { Id = data.RemoteId, ModifiedAt = data.ModifiedAt.ToUtc (), Name = data.Name, IsPremium = data.IsPremium, DefaultRate = data.DefaultRate, DefaultCurrency = data.DefaultCurrency, OnlyAdminsMayCreateProjects = data.ProjectCreationPrivileges == AccessLevel.Admin, OnlyAdminsSeeBillableRates = data.BillableRatesVisibility == AccessLevel.Admin, RoundingMode = data.RoundingMode, RoundingPercision = data.RoundingPercision, LogoUrl = data.LogoUrl, }; }
private void CreateTestData () { RunAsync (async delegate { workspace = await DataStore.PutAsync (new WorkspaceData () { RemoteId = 1, Name = "Unit Testing", IsDirty = true, }); user = await DataStore.PutAsync (new UserData () { RemoteId = 1, Name = "Tester", DefaultWorkspaceId = workspace.Id, IsDirty = true, }); var project = await DataStore.PutAsync (new ProjectData () { RemoteId = 1, Name = "Ad design", WorkspaceId = workspace.Id, IsDirty = true, }); await DataStore.PutAsync (new TimeEntryData () { RemoteId = 1, Description = "Initial concept", State = TimeEntryState.Finished, StartTime = new DateTime (2013, 01, 01, 09, 12, 0, DateTimeKind.Utc), StopTime = new DateTime (2013, 01, 01, 10, 1, 0, DateTimeKind.Utc), ProjectId = project.Id, WorkspaceId = workspace.Id, UserId = user.Id, IsDirty = true, }); await DataStore.PutAsync (new TimeEntryData () { RemoteId = 2, Description = "Breakfast", State = TimeEntryState.Finished, StartTime = new DateTime (2013, 01, 01, 10, 12, 0, DateTimeKind.Utc), StopTime = new DateTime (2013, 01, 01, 10, 52, 0, DateTimeKind.Utc), WorkspaceId = workspace.Id, UserId = user.Id, IsDirty = true, }); }); }
public void TestObjectCreation () { RunAsync (async delegate { var obj1 = new WorkspaceData () { Name = "Test", }; var obj2 = await DataStore.PutAsync (obj1); Assert.AreNotSame (obj1, obj2, "Put should return a new instance of the object."); Assert.AreNotEqual (obj1.Id, obj2.Id, "Primary key was not set!"); // Verify that single message was sent Assert.That (messages, Has.Count.EqualTo (1)); Assert.That (messages, Has.Exactly (1) .Matches<DataChangeMessage> (msg => msg.Action == DataAction.Put && obj2.Matches (msg.Data))); }); }
public override void SetUp () { base.SetUp (); RunAsync (async delegate { workspace = await DataStore.PutAsync (new WorkspaceData () { Name = "Test", RemoteId = 9999 }); user = await DataStore.PutAsync (new UserData () { Name = "John Doe", TrackingMode = TrackingMode.StartNew, DefaultWorkspaceId = workspace.Id, StartOfWeek = DayOfWeek.Monday, }); await SetUpFakeUser (user.Id); // configure IReportClient service var serviceMock = new Mock<IReportsClient>(); startTime = ResolveStartDate ( DateTime.Now, ZoomLevel.Week, user); endTime = ResolveEndDate ( startTime, ZoomLevel.Week); serviceMock.Setup ( x => x.GetReports ( startTime, endTime, Convert.ToInt64 ( workspace.RemoteId))) .Returns ( Task.FromResult (CreateEmptyReportJson ( ZoomLevel.Week, startTime))); startTime = ResolveStartDate ( DateTime.Now, ZoomLevel.Month, user); endTime = ResolveEndDate ( startTime, ZoomLevel.Month); serviceMock.Setup ( x => x.GetReports ( startTime, endTime, Convert.ToInt64 ( workspace.RemoteId))) .Returns ( Task.FromResult (CreateEmptyReportJson ( ZoomLevel.Month, startTime))); startTime = ResolveStartDate ( DateTime.Now, ZoomLevel.Year, user); endTime = ResolveEndDate ( startTime, ZoomLevel.Year); serviceMock.Setup ( x => x.GetReports ( startTime, endTime, Convert.ToInt64 ( workspace.RemoteId))) .Returns ( Task.FromResult (CreateEmptyReportJson ( ZoomLevel.Year, startTime))); ServiceContainer.Register<IReportsClient> (serviceMock.Object); ServiceContainer.Register<ReportJsonConverter> (); }); }
public WorkspaceData Import (IDataStoreContext ctx, WorkspaceJson json, Guid? localIdHint = null, WorkspaceData mergeBase = null) { var log = ServiceContainer.Resolve<ILogger> (); var data = GetByRemoteId<WorkspaceData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new WorkspaceMerger (mergeBase) : null; if (merger != null && data != null) { merger.Add (new WorkspaceData (data)); } if (json.DeletedAt.HasValue) { if (data != null) { log.Info (Tag, "Deleting local data for {0}.", data.ToIdString ()); ctx.Delete (data); data = null; } } else if (merger != null || ShouldOverwrite (data, json)) { data = data ?? new WorkspaceData (); ImportJson (data, json); if (merger != null) { merger.Add (data); data = merger.Result; } if (merger != null) { log.Info (Tag, "Importing {0}, merging with local data.", data.ToIdString ()); } else { log.Info (Tag, "Importing {0}, replacing local data.", data.ToIdString ()); } data = ctx.Put (data); } else { log.Info (Tag, "Skipping import of {0}.", json.ToIdString ()); } return data; }
public override void SetUp () { base.SetUp (); RunAsync (async delegate { workspace = await DataStore.PutAsync (new WorkspaceData () { Name = "Test", }); user = await DataStore.PutAsync (new UserData () { Name = "John Doe", TrackingMode = TrackingMode.StartNew, DefaultWorkspaceId = workspace.Id, }); await SetUpFakeUser (user.Id); ServiceContainer.Register<ISyncManager> (Mock.Of<ISyncManager> ( (mgr) => mgr.IsRunning == syncManagerRunning)); ServiceContainer.Register<ActiveTimeEntryManager> (new ActiveTimeEntryManager ()); }); }
public void TestFailedDelete () { RunAsync (async delegate { // Create non-existing object var obj1 = new WorkspaceData () { Id = Guid.NewGuid (), Name = "Test", }; // Delete it var success = await DataStore.DeleteAsync (obj1); Assert.IsFalse (success, "Delete should've failed."); Assert.That (messages, Has.Count.EqualTo (0)); }); }
private async Task CreateTestData () { workspace = await DataStore.PutAsync (new WorkspaceData () { RemoteId = 1, Name = "Unit Testing", }); user = await DataStore.PutAsync (new UserData () { RemoteId = 1, Name = "Tester", DefaultWorkspaceId = workspace.Id, }); var project = await DataStore.PutAsync (new ProjectData () { RemoteId = 1, Name = "Ad design", WorkspaceId = workspace.Id, }); await DataStore.PutAsync (new TimeEntryData () { RemoteId = 1, Description = "Initial concept", State = TimeEntryState.Finished, StartTime = MakeTime (09, 12), StopTime = MakeTime (10, 1), ProjectId = project.Id, WorkspaceId = workspace.Id, UserId = user.Id, }); await DataStore.PutAsync (new TimeEntryData () { RemoteId = 2, Description = "Breakfast", State = TimeEntryState.Finished, StartTime = MakeTime (10, 5), StopTime = MakeTime (10, 30), WorkspaceId = workspace.Id, UserId = user.Id, }); await DataStore.PutAsync (new TimeEntryData () { RemoteId = 3, Description = "Initial concept", State = TimeEntryState.Finished, StartTime = MakeTime (10, 35), StopTime = MakeTime (12, 21), ProjectId = project.Id, WorkspaceId = workspace.Id, UserId = user.Id, }); await DataStore.PutAsync (new TimeEntryData () { RemoteId = 4, State = TimeEntryState.Finished, StartTime = MakeTime (12, 25), StopTime = MakeTime (13, 57), ProjectId = project.Id, WorkspaceId = workspace.Id, UserId = user.Id, }); await DataStore.PutAsync (new TimeEntryData () { RemoteId = 5, State = TimeEntryState.Finished, StartTime = MakeTime (14, 0), StopTime = MakeTime (14, 36), WorkspaceId = workspace.Id, UserId = user.Id, }); }
public static WorkspaceData Import (this WorkspaceJson json, IDataStoreContext ctx, Guid? localIdHint = null, WorkspaceData mergeBase = null) { var converter = ServiceContainer.Resolve<WorkspaceJsonConverter> (); return converter.Import (ctx, json, localIdHint, mergeBase); }