public async Task UpdateToDoItemTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var(userName, client) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await client.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.CreateToDoGroup)) .Set(new ToDoGroupsController.CreateToDoGroupArgs { title = "Test" }) .ExecuteAsSingleAsync(); ToDoItemDto toDoItem = await client.Controller <ToDoItemsController, ToDoItemDto>() .Set(new ToDoItemDto { Title = "Task1", Notes = "Hi this is the first sample", ToDoGroupId = toDoGroup.Id }) .InsertEntryAsync(); toDoItem.Title += "!"; toDoItem.IsCompleted = true; ToDoItemDto updatedToDoItem = await client.Controller <ToDoItemsController, ToDoItemDto>() .Key(toDoItem.Id) .Set(toDoItem) .UpdateEntryAsync(); Assert.AreEqual("Task1!", updatedToDoItem.Title); Assert.AreEqual(true, updatedToDoItem.IsCompleted); Assert.AreEqual(userName, updatedToDoItem.CompletedBy); } }
public async Task ShareToDoGroupWithAnotherUserTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var toDoLineClient = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await toDoLineClient.ODataClient.ToDoGroups() .CreateToDoGroup("Test") .ExecuteAsSingleAsync(); var toDoLineClient2 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); UserDto user2 = await toDoLineClient.ODataClient.GetUserByUserName(toDoLineClient2.UserName); await toDoLineClient.ODataClient.ToDoGroups() .ShareToDoGroupWithAnotherUser(anotherUserId: user2.Id, toDoGroupId: toDoGroup.Id) .ExecuteAsync(); var toDoGroups = (await toDoLineClient2.ODataClient.ToDoGroups() .GetMyToDoGroups() .FindEntriesAsync()).ToArray(); Assert.AreEqual(1, toDoGroups.Length); } }
public async Task UpdateToDoItemToDoGroupIdIsNotSupportedTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var(userName, client) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoItemDto toDoItem = await client.Controller <ToDoItemsController, ToDoItemDto>() .Set(new ToDoItemDto { Title = "Task1", Notes = "Hi this is the first sample", ToDoGroupId = null }) .InsertEntryAsync(); toDoItem.Title += "!"; toDoItem.IsCompleted = true; toDoItem.ToDoGroupId = Guid.NewGuid(); try { await client.Controller <ToDoItemsController, ToDoItemDto>() .Key(toDoItem.Id) .Set(toDoItem) .UpdateEntryAsync(); Assert.Fail(); } catch (WebRequestException exp) when(exp.Message == "KnownError" && JToken.Parse(exp.Response)["error"]["message"].Value <string>() == "ChangingToDoGroupIdIsNotSupportedAtTheMoment") { } } }
public async Task KickUserFromToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var toDoLineClient1 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); string userName2 = await testEnv.RegisterNewUser(); //create ToDoGroup by first user ToDoGroupDto toDoGroup = await toDoLineClient1.ODataClient.ToDoGroups() .CreateToDoGroup("Group1") .ExecuteAsSingleAsync(); UserDto user2 = await toDoLineClient1.ODataClient.GetUserByUserName(userName2); await toDoLineClient1.ODataClient.ToDoGroups() .ShareToDoGroupWithAnotherUser(anotherUserId: user2.Id, toDoGroupId: toDoGroup.Id) .ExecuteAsSingleAsync(); await toDoLineClient1.ODataClient.ToDoGroups() .KickUserFromToDoGroup(userId: user2.Id, toDoGroupId: toDoGroup.Id) .ExecuteAsSingleAsync(); ToDoGroupDto toDoGroupK = await toDoLineClient1.ODataClient.ToDoGroups() .GetMyToDoGroups() .Filter(tdg => toDoGroup.Id == tdg.Id) .FindEntryAsync(); Assert.AreEqual(1, toDoGroupK.SharedByCount); } }
public async Task CreatingToDoItemShouldCreateToDoItemOptionsPerUserTest() { using ToDoLineTestEnv testEnv = new ToDoLineTestEnv(); ToDoLineClient toDoLineClient1 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await toDoLineClient1.ODataClient.ToDoGroups() .CreateToDoGroup("Test") .ExecuteAsSingleAsync(); ToDoLineClient toDoLineClient2 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); UserDto user2 = await toDoLineClient1.ODataClient.GetUserByUserName(toDoLineClient2.UserName); await toDoLineClient1.ODataClient.ToDoGroups() .ShareToDoGroupWithAnotherUser(anotherUserId: user2.Id, toDoGroupId: toDoGroup.Id) .ExecuteAsync(); ToDoItemDto toDoItem = await toDoLineClient2.ODataClient.ToDoItems() .Set(new ToDoItemDto { Title = "Task1", Notes = "Hi this is the first sample", ToDoGroupId = toDoGroup.Id }) .InsertEntryAsync(); bool hasToDoItem = (await toDoLineClient1.ODataClient.ToDoItems() .GetMyToDoItems() .FindEntriesAsync()).Any(); Assert.AreEqual(true, hasToDoItem); }
public async Task UpdateToDoItemTest() { using ToDoLineTestEnv testEnv = new ToDoLineTestEnv(); ToDoLineClient toDoLineClient = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await toDoLineClient.ODataClient.ToDoGroups() .CreateToDoGroup("Test") .ExecuteAsSingleAsync(); ToDoItemDto toDoItem = await toDoLineClient.ODataClient.ToDoItems() .Set(new ToDoItemDto { Title = "Task1", Notes = "Hi this is the first sample", ToDoGroupId = toDoGroup.Id }) .InsertEntryAsync(); toDoItem.Title += "!"; toDoItem.IsCompleted = true; ToDoItemDto updatedToDoItem = await toDoLineClient.ODataClient.ToDoItems() .Key(toDoItem.Id) .Set(toDoItem) .UpdateEntryAsync(); Assert.AreEqual("Task1!", updatedToDoItem.Title); Assert.AreEqual(true, updatedToDoItem.IsCompleted); Assert.AreEqual(toDoLineClient.UserName, updatedToDoItem.CompletedBy); }
public async Task OnlyOwnerCanDeleteTheToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var loginResult1 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await loginResult1.ODataClient.ToDoGroups() .CreateToDoGroup("Test") .ExecuteAsSingleAsync(); var loginResult2 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); UserDto user2 = await loginResult1.ODataClient.GetUserByUserName(loginResult2.UserName); await loginResult1.ODataClient.ToDoGroups() .ShareToDoGroupWithAnotherUser(anotherUserId: user2.Id, toDoGroupId: toDoGroup.Id) .ExecuteAsync(); toDoGroup = (await loginResult2.ODataClient.ToDoGroups() .GetMyToDoGroups() .FindEntriesAsync()).Single(); try { await loginResult2.ODataClient.ToDoGroups() .Key(toDoGroup.Id) .DeleteEntryAsync(); Assert.Fail(); } catch (WebRequestException exp) when(exp.Message == "KnownError" && JToken.Parse(exp.Response)["error"]["message"].Value <string>() == "OnlyOwnerCanDeleteTheToDoGroup") { } } }
/// <summary> /// Login with provided user name. If registerNewUserByRandomUserName gets provided 'true' then it calls <see cref="RegisterNewUser(ToDoLineTestEnv, string)"/> first. /// You've to either provide a valid userName or pass registerNewUserByRandomUserName 'true'. It generates a random userName and returns that to you in case no userName is provided for registration. /// </summary> public static async Task <ToDoLineClient> LoginInToApp(this ToDoLineTestEnv testEnv, bool registerNewUserByRandomUserName, string userName = null, string password = "******") { if (registerNewUserByRandomUserName == true) { userName = await RegisterNewUser(testEnv, userName); } else { if (userName == null) { throw new ArgumentNullException(nameof(userName)); } } Token token = await testEnv.Server.LoginWithCredentials(userName, password : password, clientId : "ToDoLine", secret : "secret"); IODataClient odataClient = testEnv.Server.BuildODataClient(odataRouteName: "ToDoLine", token: token, odataClientSettings: new ODataClientSettings { MetadataDocument = ToDoLineMetadata.MetadataString }); return(new ToDoLineClient { UserName = userName, ODataClient = odataClient, Token = token }); }
public async Task OnlyOwnerCanKickUsersFromToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var toDoLineClient1 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); var toDoLineClient2 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); //create ToDoGroup by first user ToDoGroupDto toDoGroup = await toDoLineClient1.ODataClient.ToDoGroups() .CreateToDoGroup("Group1") .ExecuteAsSingleAsync(); UserDto user2 = await toDoLineClient1.ODataClient.GetUserByUserName(toDoLineClient2.UserName); await toDoLineClient1.ODataClient.ToDoGroups() .ShareToDoGroupWithAnotherUser(anotherUserId: user2.Id, toDoGroupId: toDoGroup.Id) .ExecuteAsSingleAsync(); UserDto user1 = await toDoLineClient2.ODataClient.GetUserByUserName(toDoLineClient2.UserName); try { await toDoLineClient2.ODataClient.ToDoGroups() .KickUserFromToDoGroup(userId: user1.Id, toDoGroupId: toDoGroup.Id) .ExecuteAsSingleAsync(); Assert.Fail(); } catch (WebRequestException exp) when(exp.Message == "KnownError" && JToken.Parse(exp.Response)["error"]["message"].Value <string>() == "OnlyOwnerCanKickOtherUsers") { } } }
public async Task ActiveShowInMyDayToDoItemTest() { using ToDoLineTestEnv testEnv = new ToDoLineTestEnv(new TestEnvironmentArgs { AdditionalDependencies = (dependencyManager, services) => { IDateTimeProvider dateTimeProvider = A.Fake <IDateTimeProvider>(); A.CallTo(() => dateTimeProvider.GetCurrentUtcDateTime()) .Returns(new DateTimeOffset(2018, 1, 1, 10, 10, 10, TimeSpan.Zero)); dependencyManager.RegisterInstance(dateTimeProvider); } }); ToDoLineClient toDoLineClient = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); UserDto user = await toDoLineClient.ODataClient.GetUserByUserName(toDoLineClient.UserName); ToDoGroupDto toDoGroup = await toDoLineClient.ODataClient.ToDoGroups() .CreateToDoGroup("Test") .ExecuteAsSingleAsync(); ToDoItemDto toDoItem = await toDoLineClient.ODataClient.ToDoItems() .Set(new ToDoItemDto { Title = "Task1", Notes = "Hi this is the first sample", ShowInMyDay = true, ToDoGroupId = toDoGroup.Id }) .InsertEntryAsync(); Assert.AreEqual("Task1", toDoItem.Title); Assert.AreEqual(true, toDoItem.ShowInMyDay); }
public async Task ShareToDoGroupWithAnotherUserTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var(userName1, client1) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.CreateToDoGroup)) .Set(new ToDoGroupsController.CreateToDoGroupArgs { title = "Test" }) .ExecuteAsSingleAsync(); var(userName2, client2) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); UserDto user2 = await client1.GetUserByUserName(userName2); await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.ShareToDoGroupWithAnotherUser)) .Set(new ToDoGroupsController.ShareToDoGroupWithAnotherUserArgs { anotherUserId = user2.Id, toDoGroupId = toDoGroup.Id }) .ExecuteAsync(); var toDoGroups = (await client2.Controller <ToDoGroupsController, ToDoGroupDto>() .Function(nameof(ToDoGroupsController.GetMyToDoGroups)) .FindEntriesAsync()).ToArray(); Assert.AreEqual(1, toDoGroups.Length); } }
public async Task UpdateToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv(new TestEnvironmentArgs { AdditionalDependencies = (dependencyManager, services) => { IDateTimeProvider dateTimeProvider = A.Fake <IDateTimeProvider>(); A.CallTo(() => dateTimeProvider.GetCurrentUtcDateTime()) .Returns(new DateTimeOffset(2018, 1, 1, 10, 10, 10, TimeSpan.Zero)); dependencyManager.RegisterInstance(dateTimeProvider); } })) { var toDoLineClient = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await toDoLineClient.ODataClient.ToDoGroups() .CreateToDoGroup("Test") .ExecuteAsSingleAsync(); toDoGroup.Title += "?"; // Test? toDoGroup.SortedBy = SortBy.Importance; toDoGroup = await toDoLineClient.ODataClient.ToDoGroups() .Key(toDoGroup.Id) .Set(toDoGroup) .UpdateEntryAsync(); Assert.AreEqual("Test?", toDoGroup.Title); Assert.AreEqual(SortBy.Importance, toDoGroup.SortedBy); Assert.AreEqual(new DateTimeOffset(2018, 1, 1, 10, 10, 10, TimeSpan.Zero), toDoGroup.ModifiedOn); } }
public async Task GetCurrentUserTest() { using ToDoLineTestEnv testEnv = new ToDoLineTestEnv(); ToDoLineClient toDoLineClient = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); UserDto currentUser = await toDoLineClient.ODataClient.Users() .GetCurrentUser() .FindEntryAsync(); Assert.AreEqual(toDoLineClient.UserName, currentUser.UserName); }
public async Task GetCurrentUserTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var loginResult = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); UserDto currentUser = await loginResult.ODataClient.Controller <UsersController, UserDto>() .Function(nameof(UsersController.GetCurrentUser)) .FindEntryAsync(); Assert.AreEqual(loginResult.UserName, currentUser.UserName); } }
public async Task KickingUserFromToDoGroupShouldRemoveItsToDoItemsTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var(userName1, client1) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); var(userName2, client2) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); //create ToDoGroup by first user ToDoGroupDto toDoGroup = await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.CreateToDoGroup)) .Set(new ToDoGroupsController.CreateToDoGroupArgs { title = "Group1" }) .ExecuteAsSingleAsync(); ToDoItemDto toDoItem = await client1.Controller <ToDoItemsController, ToDoItemDto>() .Set(new ToDoItemDto { Title = "Test1", ToDoGroupId = toDoGroup.Id }) .InsertEntryAsync(); UserDto user2 = await client1.GetUserByUserName(userName2); await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.ShareToDoGroupWithAnotherUser)) .Set(new ToDoGroupsController.ShareToDoGroupWithAnotherUserArgs { anotherUserId = user2.Id, toDoGroupId = toDoGroup.Id }) .ExecuteAsSingleAsync(); await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.KickUserFromToDoGroup)) .Set(new ToDoGroupsController.KickAnotherUserFromMyToDoGroupArge { userId = user2.Id, toDoGroupId = toDoGroup.Id }) .ExecuteAsSingleAsync(); ToDoGroupDto toDoGroupK = await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Function(nameof(ToDoGroupsController.GetMyToDoGroups)) .Filter(tdg => toDoGroup.Id == tdg.Id) .FindEntryAsync(); bool hasToDoItem = (await client2.Controller <ToDoItemsController, ToDoItemDto>() .Function(nameof(ToDoItemsController.GetMyToDoItems)) .FindEntriesAsync()).Any(); Assert.AreEqual(1, toDoGroupK.SharedByCount); Assert.AreEqual(false, hasToDoItem); } }
/// <summary> /// Registers new user. If userName gets provided, it uses that for registration. Otherwise, it creates random user name. /// </summary> /// <returns>UserName. Useful when you've not provided fixed user name, so you can retrive generated user name's value.</returns> public static async Task <string> RegisterNewUser(this ToDoLineTestEnv testEnv, string userName = null, string password = "******") { userName = userName ?? Guid.NewGuid().ToString("N"); IODataClient client = testEnv.Server.BuildODataClient(odataRouteName: "ToDoLine"); await client.UserRegistration() .Register(new UserRegistrationDto { UserName = userName, Password = password }) .ExecuteAsync(); return(userName); }
public async Task CreateToDoItemWithoutToDoGroupTest() { using ToDoLineTestEnv testEnv = new ToDoLineTestEnv(); ToDoLineClient toDoLineClient = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoItemDto toDoItem = await toDoLineClient.ODataClient.ToDoItems() .Set(new ToDoItemDto { Title = "Task1", Notes = "Hi this is the first sample", ToDoGroupId = null }) .InsertEntryAsync(); Assert.AreEqual("Task1", toDoItem.Title); }
public async Task CreateToDoItemWithoutToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var(userName, client) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoItemDto toDoItem = await client.Controller <ToDoItemsController, ToDoItemDto>() .Set(new ToDoItemDto { Title = "Task1", Notes = "Hi this is the first sample", ToDoGroupId = null }) .InsertEntryAsync(); Assert.AreEqual("Task1", toDoItem.Title); } }
/// <summary> /// Registers new user. If userName gets provided, it uses that for registration. Otherwise, it creates random user name. /// </summary> /// <returns>UserName. Useful when you've not provided fixed user name, so you can retrive generated user name's value.</returns> public static async Task <string> RegisterNewUser(this ToDoLineTestEnv testEnv, string userName = null) { userName = userName ?? Guid.NewGuid().ToString("N"); IODataClient client = testEnv.Server.BuildODataClient(odataRouteName: "ToDoLine"); await client.Controller <UserRegistrationController, UserRegistrationDto>() .Action(nameof(UserRegistrationController.Register)) .Set(new UserRegistrationController.RegisterArgs { userRegistration = new UserRegistrationDto { UserName = userName, Password = "******" } }) .ExecuteAsync(); return(userName); }
public async Task SharingToDoGroupWithAnotherUserShouldShareItsToDoItemsTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var loginResult1 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await loginResult1.ODataClient.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.CreateToDoGroup)) .Set(new ToDoGroupsController.CreateToDoGroupArgs { title = "Test" }) .ExecuteAsSingleAsync(); ToDoItemDto toDoItem = await loginResult1.ODataClient.Controller <ToDoItemsController, ToDoItemDto>() .Set(new ToDoItemDto { Title = "Test1", ToDoGroupId = toDoGroup.Id }) .InsertEntryAsync(); var loginResult2 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); UserDto user2 = await loginResult1.ODataClient.GetUserByUserName(loginResult2.UserName); await loginResult1.ODataClient.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.ShareToDoGroupWithAnotherUser)) .Set(new ToDoGroupsController.ShareToDoGroupWithAnotherUserArgs { anotherUserId = user2.Id, toDoGroupId = toDoGroup.Id }) .ExecuteAsync(); ToDoGroupDto[] toDoGroups = (await loginResult2.ODataClient.Controller <ToDoGroupsController, ToDoGroupDto>() .Function(nameof(ToDoGroupsController.GetMyToDoGroups)) .FindEntriesAsync()).ToArray(); ToDoItemDto[] toDoItems = (await loginResult2.ODataClient.Controller <ToDoItemsController, ToDoItemDto>() .Function(nameof(ToDoItemsController.GetMyToDoItems)) .FindEntriesAsync()).ToArray(); Assert.AreEqual(1, toDoGroups.Length); Assert.AreEqual(1, toDoItems.Length); } }
public async Task DeleteToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var toDoLineClient = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await toDoLineClient.ODataClient.ToDoGroups() .CreateToDoGroup("test") .ExecuteAsSingleAsync(); await toDoLineClient.ODataClient.ToDoGroups() .Key(toDoGroup.Id) .DeleteEntryAsync(); Assert.AreEqual(0, (await toDoLineClient.ODataClient.ToDoGroups() .GetMyToDoGroups() .FindEntriesAsync()).Count()); } }
public async Task OnlyOwnerCanKickUsersFromToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var(userName1, client1) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); var(userName2, client2) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); //create ToDoGroup by first user ToDoGroupDto toDoGroup = await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.CreateToDoGroup)) .Set(new ToDoGroupsController.CreateToDoGroupArgs { title = "Group1" }) .ExecuteAsSingleAsync(); UserDto user2 = await client1.GetUserByUserName(userName2); await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.ShareToDoGroupWithAnotherUser)) .Set(new ToDoGroupsController.ShareToDoGroupWithAnotherUserArgs { anotherUserId = user2.Id, toDoGroupId = toDoGroup.Id }) .ExecuteAsSingleAsync(); UserDto user1 = await client2.GetUserByUserName(userName2); try { await client2.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.KickUserFromToDoGroup)) .Set(new ToDoGroupsController.KickAnotherUserFromMyToDoGroupArge { userId = user1.Id, toDoGroupId = toDoGroup.Id }) .ExecuteAsSingleAsync(); Assert.Fail(); } catch (WebRequestException exp) when(exp.Message == "KnownError" && JToken.Parse(exp.Response)["error"]["message"].Value <string>() == "OnlyOwnerCanKickOtherUsers") { } } }
public async Task CreateToDoItemTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var loginResult = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await loginResult.ODataClient.ToDoGroups() .CreateToDoGroup("Test") .ExecuteAsSingleAsync(); ToDoItemDto toDoItem = await loginResult.ODataClient.ToDoItems() .Set(new ToDoItemDto { Title = "Task1", Notes = "Hi this is the first sample", ToDoGroupId = toDoGroup.Id }) .InsertEntryAsync(); Assert.AreEqual("Task1", toDoItem.Title); } }
public async Task KickingUserFromToDoGroupShouldRemoveItsToDoItemsTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var toDoLineClient1 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); var toDoLineClient2 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); //create ToDoGroup by first user ToDoGroupDto toDoGroup = await toDoLineClient1.ODataClient.ToDoGroups() .CreateToDoGroup("Group1") .ExecuteAsSingleAsync(); ToDoItemDto toDoItem = await toDoLineClient1.ODataClient.ToDoItems() .Set(new ToDoItemDto { Title = "Test1", ToDoGroupId = toDoGroup.Id }) .InsertEntryAsync(); UserDto user2 = await toDoLineClient1.ODataClient.GetUserByUserName(toDoLineClient2.UserName); await toDoLineClient1.ODataClient.ToDoGroups() .ShareToDoGroupWithAnotherUser(toDoGroupId: toDoGroup.Id, anotherUserId: user2.Id) .ExecuteAsSingleAsync(); await toDoLineClient1.ODataClient.ToDoGroups() .KickUserFromToDoGroup(userId: user2.Id, toDoGroupId: toDoGroup.Id) .ExecuteAsSingleAsync(); ToDoGroupDto toDoGroupK = await toDoLineClient1.ODataClient.ToDoGroups() .GetMyToDoGroups() .Filter(tdg => toDoGroup.Id == tdg.Id) .FindEntryAsync(); bool hasToDoItem = (await toDoLineClient2.ODataClient.ToDoItems() .GetMyToDoItems() .FindEntriesAsync()).Any(); Assert.AreEqual(1, toDoGroupK.SharedByCount); Assert.AreEqual(false, hasToDoItem); } }
public async Task CreateToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var toDoLineClient = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto addedToDoGroup = await toDoLineClient.ODataClient.ToDoGroups() .CreateToDoGroup("Test") .ExecuteAsSingleAsync(); Assert.AreEqual(1, addedToDoGroup.SharedByCount); Assert.AreEqual("Test", addedToDoGroup.Title); var toDoGroups = (await toDoLineClient.ODataClient.ToDoGroups() .GetMyToDoGroups() .FindEntriesAsync()).ToArray(); Assert.AreEqual(1, toDoGroups.Length); } }
public async Task DeleteToDoItemTest() { using ToDoLineTestEnv testEnv = new ToDoLineTestEnv(); ToDoLineClient toDoLineClient = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await toDoLineClient.ODataClient.ToDoGroups() .CreateToDoGroup("Test") .ExecuteAsSingleAsync(); ToDoItemDto toDoItem = await toDoLineClient.ODataClient.ToDoItems() .Set(new ToDoItemDto { Title = "Task1", Notes = "Hi this is the first sample", ToDoGroupId = toDoGroup.Id }) .InsertEntryAsync(); await toDoLineClient.ODataClient.ToDoItems() .Key(toDoItem.Id) .DeleteEntryAsync(); }
public async Task OnlyOwnerCanDeleteTheToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var(userName1, client1) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.CreateToDoGroup)) .Set(new ToDoGroupsController.CreateToDoGroupArgs { title = "Test" }) .ExecuteAsSingleAsync(); var(userName2, client2) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); UserDto user2 = await client1.GetUserByUserName(userName2); await client1.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.ShareToDoGroupWithAnotherUser)) .Set(new ToDoGroupsController.ShareToDoGroupWithAnotherUserArgs { anotherUserId = user2.Id, toDoGroupId = toDoGroup.Id }) .ExecuteAsync(); toDoGroup = (await client2.Controller <ToDoGroupsController, ToDoGroupDto>() .Function(nameof(ToDoGroupsController.GetMyToDoGroups)) .FindEntriesAsync()).Single(); try { await client2.Controller <ToDoGroupsController, ToDoGroupDto>() .Key(toDoGroup.Id) .DeleteEntryAsync(); Assert.Fail(); } catch (WebRequestException exp) when(exp.Message == "KnownError" && JToken.Parse(exp.Response)["error"]["message"].Value <string>() == "OnlyOwnerCanDeleteTheToDoGroup") { } } }
public async Task KickUserFromToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var loginResult1 = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); string userName2 = await testEnv.RegisterNewUser(); //create ToDoGroup by first user ToDoGroupDto toDoGroup = await loginResult1.ODataClient.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.CreateToDoGroup)) .Set(new ToDoGroupsController.CreateToDoGroupArgs { title = "Group1" }) .ExecuteAsSingleAsync(); UserDto user2 = await loginResult1.ODataClient.GetUserByUserName(userName2); await loginResult1.ODataClient.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.ShareToDoGroupWithAnotherUser)) .Set(new ToDoGroupsController.ShareToDoGroupWithAnotherUserArgs { anotherUserId = user2.Id, toDoGroupId = toDoGroup.Id }) .ExecuteAsSingleAsync(); await loginResult1.ODataClient.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.KickUserFromToDoGroup)) .Set(new ToDoGroupsController.KickAnotherUserFromMyToDoGroupArge { userId = user2.Id, toDoGroupId = toDoGroup.Id }) .ExecuteAsSingleAsync(); ToDoGroupDto toDoGroupK = await loginResult1.ODataClient.Controller <ToDoGroupsController, ToDoGroupDto>() .Function(nameof(ToDoGroupsController.GetMyToDoGroups)) .Filter(tdg => toDoGroup.Id == tdg.Id) .FindEntryAsync(); Assert.AreEqual(1, toDoGroupK.SharedByCount); } }
/// <summary> /// Login with provided user name. If registerNewUserByRandomUserName gets provided 'true' then it calls <see cref="RegisterNewUser(ToDoLineTestEnv, string)"/> first. /// You've to either provide a valid userName or pass registerNewUserByRandomUserName 'true'. It generates a random userName and returns that to you in case no userName is provided for registration. /// </summary> public static async Task <LoginResult> LoginInToApp(this ToDoLineTestEnv testEnv, bool registerNewUserByRandomUserName, string userName = null, string password = "******") { if (registerNewUserByRandomUserName == true) { userName = await RegisterNewUser(testEnv, userName); } else { if (userName == null) { throw new ArgumentNullException(nameof(userName)); } } TokenResponse token = await testEnv.Server.Login(userName, password : password, clientId : "ToDoLine", secret : "secret"); IODataClient odataClient = testEnv.Server.BuildODataClient(odataRouteName: "ToDoLine", token: token); return(new LoginResult { UserName = userName, ODataClient = odataClient, Token = token }); }
public async Task DeleteToDoGroupTest() { using (ToDoLineTestEnv testEnv = new ToDoLineTestEnv()) { var(userName, client) = await testEnv.LoginInToApp(registerNewUserByRandomUserName : true); ToDoGroupDto toDoGroup = await client.Controller <ToDoGroupsController, ToDoGroupDto>() .Action(nameof(ToDoGroupsController.CreateToDoGroup)) .Set(new ToDoGroupsController.CreateToDoGroupArgs { title = "Test" }) .ExecuteAsSingleAsync(); await client.Controller <ToDoGroupsController, ToDoGroupDto>() .Key(toDoGroup.Id) .DeleteEntryAsync(); Assert.AreEqual(0, (await client.Controller <ToDoGroupsController, ToDoGroupDto>() .Function(nameof(ToDoGroupsController.GetMyToDoGroups)) .FindEntriesAsync()).Count()); } }