public override void Setup() { base.Setup(); _user = new { }; _processor = new RealmiusServerProcessor <object>(new ShareEverythingConfiguration(_contextFunc, typeof(DbSyncObject))); }
public void UploadData_CheckAndProcessCanRetrieveUnmodifiedEntityFromDatabase() { _contextFunc().DbSyncObjectWithIgnoredFields.Count().Should().Be(0); var config = new Mock <ShareEverythingConfiguration>(_contextFunc, typeof(DbSyncObjectWithIgnoredFields)) { CallBase = true }; var controller = new RealmiusServerProcessor(config.Object); var result = controller.Upload(new UploadDataRequest() { ChangeNotifications = { new UploadRequestItem() { Type = "DbSyncObjectWithIgnoredFields", PrimaryKey = "1", SerializedObject = "{Id: '1', Text: '123', Tags: 'zxc'}", } } }, null); CheckNoError(result); config.Setup( x => x.CheckAndProcess(It.IsAny <CheckAndProcessArgs <object> >())) .Returns((CheckAndProcessArgs <object> args) => { var localDb = (LocalDbContext)args.Database; var dbObj = (DbSyncObjectWithIgnoredFields)args.OriginalDbEntity; dbObj.Text.Should().Be("123"); ((DbSyncObjectWithIgnoredFields)args.Entity).Text.Should().Be("asd"); return(true); }); var result2 = controller.Upload(new UploadDataRequest() { ChangeNotifications = { new UploadRequestItem() { Type = "DbSyncObjectWithIgnoredFields", PrimaryKey = "1", SerializedObject = "{Id: '1', Text: 'asd', Tags: 'zxc'}", } } }, null); CheckNoError(result2); config.VerifyAll(); var db2 = _contextFunc(); var obj2 = db2.DbSyncObjectWithIgnoredFields.First(); obj2.Text.Should().Be("asd"); obj2.Tags.Should().BeNullOrEmpty(); }
public void Upload_Delete_UploadAgain() { var controller = new RealmiusServerProcessor(new ShareEverythingConfiguration(_contextFunc, typeof(DbSyncObject))); Func <DownloadDataResponse> getDownloaded = () => controller.Download(new DownloadDataRequest() { Types = new[] { nameof(DbSyncObject) }, }, new { }); Func <string> dataToCompare = () => { var data = getDownloaded(); return(string.Join(", ", data.ChangedObjects.Select(x => $"{x.IsDeleted}"))); }; var objectToSave = new DbSyncObject() { Text = "123123123", Id = Guid.NewGuid().ToString() }; var result1 = controller.Upload(new UploadDataRequest() { ChangeNotifications = { new UploadRequestItem() { Type = nameof(DbSyncObject), PrimaryKey = objectToSave.MobilePrimaryKey, SerializedObject = JsonConvert.SerializeObject(objectToSave), //IsDeleted = true, } } }, null); dataToCompare().Should().BeEquivalentTo("False"); var result2 = controller.Upload(new UploadDataRequest() { ChangeNotifications = { new UploadRequestItem() { Type = nameof(DbSyncObject), PrimaryKey = objectToSave.MobilePrimaryKey, SerializedObject = "", IsDeleted = true, } } }, null); //dataToCompare().Should().BeEquivalentTo("True"); objectToSave.Text = "zxc"; var result3 = controller.Upload(new UploadDataRequest() { ChangeNotifications = { new UploadRequestItem() { Type = nameof(DbSyncObject), PrimaryKey = objectToSave.MobilePrimaryKey, SerializedObject = JsonConvert.SerializeObject(objectToSave), IsDeleted = false, } } }, null); dataToCompare().Should().BeEquivalentTo("False"); }
public void ManyToManyRef() { var db = _contextFunc(); var controller = new RealmiusServerProcessor(new ShareEverythingConfiguration(_contextFunc, typeof(RefSyncObject))); var result = controller.Upload(new UploadDataRequest() { ChangeNotifications = { new UploadRequestItem() { Type = nameof(RefSyncObject), PrimaryKey = "123", SerializedObject = "{Id: '123', Text: 'zxc'}", }, new UploadRequestItem() { Type = nameof(RefSyncObject), PrimaryKey = "22", SerializedObject = "{Id: '22', Text: 'qwe'}", }, new UploadRequestItem() { Type = nameof(RefSyncObject), PrimaryKey = "456", SerializedObject = "{Id: '456', Text: 'qwe', References: ['123']}", } } }, null); result.Results.Count.Should().Be(3); string.Join(", ", result.Results.Where(x => !x.IsSuccess).Select(x => x.Error)).Should().Be(""); db = _contextFunc(); var obj0 = db.RefSyncObjects.First(x => x.Id == "123"); obj0.Text.Should().Be("zxc"); var obj = db.RefSyncObjects.First(x => x.Id == "456"); obj.Text.Should().Be("qwe"); string.Join(", ", obj.References.Select(x => x.Text)).Should().BeEquivalentTo("zxc"); var result2 = controller.Upload(new UploadDataRequest() { ChangeNotifications = { new UploadRequestItem() { Type = nameof(RefSyncObject), PrimaryKey = "456", SerializedObject = "{References:null}", } } }, null); result2.Results.Count.Should().Be(1); string.Join(", ", result2.Results.Where(x => !x.IsSuccess).Select(x => x.Error)).Should().Be(""); db = _contextFunc(); string.Join(", ", db.RefSyncObjects.First(x => x.Id == "456").References.Select(x => x.Text)).Should().BeEquivalentTo(""); var result3 = controller.Upload(new UploadDataRequest() { ChangeNotifications = { new UploadRequestItem() { Type = nameof(RefSyncObject), PrimaryKey = "456", SerializedObject = "{References:['22']}", } } }, null); result3.Results.Count.Should().Be(1); string.Join(", ", result3.Results.Where(x => !x.IsSuccess).Select(x => x.Error)).Should().Be(""); db = _contextFunc(); string.Join(", ", db.RefSyncObjects.First(x => x.Id == "456").References.Select(x => x.Text)).Should().BeEquivalentTo("qwe"); var result4 = controller.Upload(new UploadDataRequest() { ChangeNotifications = { new UploadRequestItem() { Type = nameof(RefSyncObject), PrimaryKey = "456", SerializedObject = "{References:['22', '123']}", } } }, null); result4.Results.Count.Should().Be(1); string.Join(", ", result3.Results.Where(x => !x.IsSuccess).Select(x => x.Error)).Should().Be(""); db = _contextFunc(); string.Join(", ", db.RefSyncObjects.First(x => x.Id == "456").References.Select(x => x.Text).OrderBy(x => x)).Should().BeEquivalentTo("qwe, zxc"); }