public void TestUpdateLockedObjectBySameUserWithFlag() { ActODataService(args => { var userMock = new Mock <CurrentUserService.IUser>(); userMock.Setup(u => u.Login).Returns("user1"); var lockService = new LockService(args.DataService); var offlineManager = new DefaultOfflineManager(lockService, userMock.Object); args.UnityContainer.RegisterInstance <BaseOfflineManager>(offlineManager); var лес = new Лес(); args.DataService.UpdateObject(лес); AssertLock.IsNotAcquired(lockService, лес); // Select data with locking. var result1 = args.HttpClient.GetAsync(args.Token.Model, typeof(Лес), "user1").Result; Assert.True(result1.IsSuccessStatusCode); AssertLock.IsAcquired(lockService, лес, "user1"); // Update locked data. var result2 = args.HttpClient.PatchAsJsonStringAsync(args.Token.Model, лес, Лес.Views.ЛесE, "user1").Result; Assert.True(result2.IsSuccessStatusCode); AssertLock.IsNotAcquired(lockService, лес); }); }
public void TestLockingAfterErrorInUnlocking() { ActODataService(args => { var dataObjects = new List <Лес>(); for (int i = 0; i < 10; i++) { dataObjects.Add(new Лес { Страна = new Страна() }); } var realLockService = new LockService(args.DataService); var lockServiceMock = new Mock <ILockService>(); lockServiceMock .Setup(s => s.LockObject(It.IsAny <object>(), It.IsAny <string>())) .Returns <object, string>((key, userName) => realLockService.LockObject(key, userName)); var counter = 0; lockServiceMock .Setup(s => s.UnlockObject(It.IsAny <object>())) .Returns <object>( key => { if (counter >= 5) { throw new InvalidOperationException(); } counter++; return(realLockService.UnlockObject(key)); }); var userMock = new Mock <CurrentUserService.IUser>(); var offlineManager = new DefaultOfflineManager(lockServiceMock.Object, userMock.Object); args.UnityContainer.RegisterInstance <BaseOfflineManager>(offlineManager); foreach (Лес dataObject in dataObjects) { args.DataService.UpdateObject(dataObject); AssertLock.IsNotAcquired(realLockService, dataObject); AssertLock.IsNotAcquired(realLockService, dataObject.Страна); } userMock.Setup(u => u.Login).Returns("user1"); var result = args.HttpClient.GetAsync(args.Token.Model, typeof(Лес), "user1").Result; Assert.True(result.IsSuccessStatusCode); foreach (var dataObject in dataObjects) { AssertLock.IsAcquired(realLockService, dataObject, "user1"); } }); }
public void TestAcquiringWithoutLock() { ActODataService(args => { var lockService = new LockService(args.DataService); var currentUser = new Mock <CurrentUserService.IUser>().Object; var offlineManager = new DefaultOfflineManager(lockService, currentUser); args.UnityContainer.RegisterInstance <BaseOfflineManager>(offlineManager); var лес = new Лес(); args.DataService.UpdateObject(лес); AssertLock.IsNotAcquired(lockService, лес); var result = args.HttpClient.GetAsync(args.Token.Model, typeof(Лес)).Result; Assert.True(result.IsSuccessStatusCode); AssertLock.IsNotAcquired(lockService, лес); }); }