Beispiel #1
0
        public async Task LinkCreateFail(int id)
        {
            //Arrange
            var link = new RoomUserLink()
            {
                RoomId     = 1,
                RoomUserId = id,
                UserId     = "testUser"
            };
            // Act
            var result = await RoomUserLinkDAO.Create(roomContext, link);

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);

            result = await RoomUserLinkDAO.Create(roomContext, new RoomUserLink()
            {
                RoomId     = 1,
                RoomUserId = id,
                UserId     = "testUser"
            });

            // Assert
            Assert.Equal((int)HttpStatusCode.InternalServerError, ((ObjectResult)result).StatusCode);
        }
Beispiel #2
0
 public static async Task <IActionResult> Delete(RoomDBContext context, RoomUserLink roomUserLink)
 {
     try
     {
         context.RoomUserLink.Remove(roomUserLink);
         context.SaveChanges();
         return(new ObjectResult(new { message = "success" })
         {
             StatusCode = 200,
         });
     }
     catch (Exception e)
     {
         return(new ObjectResult(new { message = e.Message })
         {
             StatusCode = 500,
         });
     }
 }
Beispiel #3
0
        public static async Task <IActionResult> Create(RoomDBContext context, RoomUserLink roomUserLink)
        {
            try
            {
                await context.RoomUserLink.AddAsync(roomUserLink);

                context.SaveChanges();
                return(new ObjectResult("success")
                {
                    StatusCode = 200,
                });
            }
            catch (Exception e)
            {
                return(new ObjectResult(e.Message)
                {
                    StatusCode = 500,
                });
            }
        }
Beispiel #4
0
        public async void DeleteTeacher_Returns_Fail_LinkedToRoom(string id)
        {
            //Arrange
            var user = new AppUser
            {
                Id       = id,
                UserName = "******",
                Email    = "Test1@gmail",
                Avatar   = "default.png",
                RealName = "Test 1",
                DOB      = new DateTime(2020, 09, 29)
            };

            var user2 = new AppUser
            {
                Id       = "4",
                UserName = "******",
                Email    = "Test4@gmail",
                Avatar   = "default.png",
                RealName = "Test 4",
                DOB      = new DateTime(2020, 09, 29)
            };

            var roomUserLink = new RoomUserLink
            {
                RoomUserId = 1,
                RoomId     = 1,
                UserId     = "4"
            };

            _roomContext.RoomUserLink.Add(roomUserLink);
            _roomContext.SaveChanges();

            List <string> list = new List <string>()
            {
                user.Id, "4"
            };
            List <string> listcheckSuccess = new List <string>()
            {
                user.Id
            };

            fakeUserManager.Setup(x => x.FindByIdAsync(user.Id)).ReturnsAsync(user);
            fakeUserManager.Setup(x => x.FindByIdAsync(user2.Id)).ReturnsAsync(user2);
            fakeUserManager.Setup(x => x.IsInRoleAsync(It.IsAny <AppUser>(), "teacher")).ReturnsAsync(true);

            //Act
            var result = await _teacherService.Object.DeleteTeacher(list);

            var okObjectResult = result as OkObjectResult;
            var model          = okObjectResult.Value as Dictionary <String, object>;
            var keys           = model.Keys.ToArray();
            var values         = model.Values.ToArray();
            var emptyList      = new List <string>()
            {
                "Teacher " + user2.UserName + " is still linked to a classroom"
            };
            var listSuccess = (List <string>)values[0];
            var listFailed  = (List <Error>)values[1];

            //Assert
            Assert.Equal(200, okObjectResult.StatusCode);
            Assert.IsType <OkObjectResult>(okObjectResult);
            Assert.Equal(2, model.Count);
            Assert.Equal("success", keys[0].ToString());
            Assert.Equal("failed", keys[1].ToString());
            Assert.Equal(listcheckSuccess, values[0]);

            //check value in dictionary
            Assert.Equal(user.Id, listSuccess[0]);
            Assert.Equal(emptyList[0], listFailed[0].Message);
        }