Exemplo n.º 1
0
        public async Task Get_WhenCalled_ReturnsOkResult()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var homes = new List <Home>
            {
                new Home()
                {
                    Name = "test_home_1",
                    Id   = Guid.NewGuid()
                },
                new Home()
                {
                    Name = "test_home_2",
                    Id   = Guid.NewGuid()
                }
            };

            mockedRepo.Setup(repo => repo.GetHomes()).ReturnsAsync(homes);

            var controller = new HomesController(mockedRepo.Object);
            var result     = await controller.Get();

            var contentResult = (result as OkObjectResult).Value as IEnumerable <Home>;

            Assert.NotNull(contentResult);
            Assert.Equal(contentResult, homes);
        }
        private void DgvNhanVien_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            HomesController homesController = new HomesController();
            DataRowView     row             = dgvNhanVien.SelectedItem as DataRowView;

            if (row != null)
            {
                txtTen.Text    = row.Row.ItemArray[1].ToString();
                txtID.Text     = row.Row.ItemArray[0].ToString();
                nvId           = Convert.ToInt32(row.Row.ItemArray[0].ToString());
                txtCMND.Text   = row.Row.ItemArray[3].ToString();
                txtdc.Text     = row.Row.ItemArray[5].ToString();
                txtSdt.Text    = row.Row.ItemArray[4].ToString();
                ngayLam.Text   = row.Row.ItemArray[6].ToString();
                ngaySinh.Text  = row.Row.ItemArray[2].ToString();
                cbxChucVu.Text = row.Row.ItemArray[7].ToString();
                cbxgt.Text     = row.Row.ItemArray[8].ToString();
                //location = row.Row.ItemArray[9].ToString();
                var bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.UriSource = new Uri(Environment.CurrentDirectory + @homesController.GetImage(Convert.ToInt32(txtID.Text)));
                bitmapImage.EndInit();
                pctbAvartar.Source = bitmapImage;
            }
        }
Exemplo n.º 3
0
        public async Task AddRoom_WhenCalled_ReturnsOk()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            var room = new Room()
            {
                Id = Guid.Parse("00000000-0000-0000-0000-000000000000")
            };

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync(newHome);
            mockedRepo.Setup(repo => repo.AddRoom(Guid.Parse("00000000-0000-0000-0000-000000000003"), room)).ReturnsAsync(room);

            var result = await controller.AddRoom("00000000-0000-0000-0000-000000000003", room);

            var contentResult = (result as OkObjectResult).Value;

            Assert.NotNull(contentResult);
            Assert.Equal(room, contentResult);
        }
        private void DgvTaiKhoan_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            HomesController homesController = new HomesController();
            DataRowView     row             = dgvTaiKhoan.SelectedItem as DataRowView;

            if (row != null)
            {
                cboTenNhanVien.Text    = row.Row.ItemArray[1].ToString();
                txtAccountUser.Text    = row.Row.ItemArray[3].ToString();
                txtEmail.Text          = row.Row.ItemArray[4].ToString();
                chkTinhTrang.IsChecked = Convert.ToBoolean(row.Row.ItemArray[5].ToString());
                try
                {
                    var bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.UriSource = new Uri(@Environment.CurrentDirectory + @homesController.GetImage(Convert.ToInt32(row.Row.ItemArray[0].ToString())));
                    bitmapImage.EndInit();
                    pctbAvatar.Source = bitmapImage;
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message, "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Exemplo n.º 5
0
        public async Task GetById_WhenCalled_UnknownID_ReturnsNotFoundResult()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var homes = new List <Home>
            {
                new Home()
                {
                    Name = "test_home_1",
                    Id   = Guid.Parse("00000000-0000-0000-0000-000000000001")
                },
                new Home()
                {
                    Name = "test_home_2",
                    Id   = Guid.Parse("00000000-0000-0000-0000-000000000002")
                }
            };

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(homes[0]);
            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000002"))).ReturnsAsync(homes[1]);

            var controller = new HomesController(mockedRepo.Object);
            var result     = await controller.Get("00000000-0000-0000-0000-000000000003");

            var contentResult = result as NotFoundResult;

            Assert.NotNull(contentResult);
        }
Exemplo n.º 6
0
        public async Task AddWeather_WhenCalled_AddFaild_ReturnsServerError()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            var weather = new Weather()
            {
                Id = Guid.Parse("00000000-0000-0000-0000-000000000000")
            };

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync(newHome);
            mockedRepo.Setup(repo => repo.AddWeather(Guid.Parse("00000000-0000-0000-0000-000000000003"), weather)).ReturnsAsync((Weather)null);

            var result = await controller.AddWeather("00000000-0000-0000-0000-000000000003", weather);

            var contentResult = (result as StatusCodeResult).StatusCode;

            Assert.Equal(StatusCodes.Status500InternalServerError, contentResult);
        }
Exemplo n.º 7
0
        public async Task AddWeather_WhenCalled_UnknownHome_ReturnsOk()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            var weather = new Weather()
            {
                Id = Guid.Parse("00000000-0000-0000-0000-000000000000")
            };

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync((Home)null);
            mockedRepo.Setup(repo => repo.AddWeather(Guid.Parse("00000000-0000-0000-0000-000000000003"), weather)).ReturnsAsync((Weather)null);

            var result = await controller.AddWeather("00000000-0000-0000-0000-000000000003", weather);

            var contentResult = result as NotFoundResult;

            Assert.NotNull(contentResult);
        }
Exemplo n.º 8
0
        public async Task GetWeather_WhenCalled_ReturnsOk()
        {
            var mockedRepo = new Mock <IHomeRepository>();
            var weather    = new List <Weather>()
            {
                new Weather()
                {
                    Id = Guid.Parse("00000000-0000-0000-0000-000000000000")
                },
                new Weather()
                {
                    Id = Guid.Parse("00000000-0000-0000-0000-000000000001")
                }
            };

            var home = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000001")
            };

            var startDate = DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0, 0));
            var endDate   = DateTime.UtcNow;

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(home);
            mockedRepo.Setup(repo => repo.GetWeather(Guid.Parse("00000000-0000-0000-0000-000000000001"), startDate, endDate)).ReturnsAsync(weather);

            var controller = new HomesController(mockedRepo.Object);
            var result     = await controller.GetWeather("00000000-0000-0000-0000-000000000001", startDate, endDate);

            var contentResult = (result as OkObjectResult).Value;

            Assert.NotNull(contentResult);
            Assert.Equal(weather, contentResult);
        }
        public void Create_ForUserThatIsAlreadyHost_MustReturnRedirectToActionResult()
        {
            //Arrange
            var userManager = UserManagerMock.New;

            userManager
            .Setup(um => um.GetUserId(It.IsAny <ClaimsPrincipal>()))
            .Returns("someId");

            var homeService = HomeServiceMock.New;

            homeService
            .Setup(hs => hs.Exists(It.IsAny <string>()))
            .Returns(true);

            var controller = new HomesController(homeService.Object, null, userManager.Object, null, null);

            //Act
            var result = controller.Create();

            //Assert
            result
            .Should()
            .BeOfType <RedirectToActionResult>()
            .Subject
            .ActionName
            .Should()
            .Be("Index");
        }
Exemplo n.º 10
0
        public async Task GetRooms_WhenCalled_UnknownHome_ReturnsNotFound()
        {
            var mockedRepo = new Mock <IHomeRepository>();
            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            var rooms = new List <Room>()
            {
                new Room()
                {
                    Id = Guid.Parse("00000000-0000-0000-0000-000000000000")
                }
            };

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync((Home)null);
            mockedRepo.Setup(repo => repo.GetRooms(newHome)).ReturnsAsync((IEnumerable <Room>)null);

            var result = await controller.GetRooms("00000000-0000-0000-0000-000000000001");

            var contentResult = result as NotFoundResult;

            Assert.NotNull(contentResult);
        }
Exemplo n.º 11
0
        public void Init()
        {
            this.ConfigureMapper();
            this.homes = new List <Home>()
            {
                new Home()
                {
                    Id         = 1,
                    Name       = "My home",
                    Activities = "ironing, fishing, etc.",
                    EndDate    = DateTime.Now.AddDays(10),
                    StartDate  = DateTime.Now.AddDays(3),
                    IsVisited  = false,
                    Notes      = "There is a disco near it",
                    Location   = new Location()
                    {
                        Id           = 1,
                        Country      = "UK",
                        LocationName = "London",
                        Latitude     = -52.58m,
                        Longitude    = -1.97m
                    },
                    PostedDate     = DateTime.Now,
                    ProfilePicture = "/Defaults/home.png",
                    Provision      = "Long table with rakia"
                },
                new Home()
                {
                    Id         = 2,
                    Name       = "House on the Sunnybeach shore",
                    Activities = "fishing, drinking, puking etc.",
                    EndDate    = DateTime.Now.AddDays(10),
                    StartDate  = DateTime.Now.AddDays(3),
                    IsVisited  = true,
                    Notes      = "There is a disco near it.",
                    Location   = new Location()
                    {
                        Id           = 1,
                        Country      = "Bulgaria",
                        LocationName = "Sunnybeach",
                        Latitude     = -52.58m,
                        Longitude    = -1.97m
                    },
                    PostedDate     = DateTime.Now,
                    ProfilePicture = "/Defaults/home.png",
                    Provision      = "Long table with rakia"
                }
            };

            this._context    = new FakeSharenestDbContext();
            this._repository = new FakeHomesRepository(this._context);
            this._service    = new HomesService(this._repository);
            this._controller = new HomesController(this._service);

            foreach (var home in homes)
            {
                this._context.Homes.Add(home);
            }
        }
        public void HomesController_GetPropertyUsingInvalidGuid_ReturnBadRequest()
        {
            HomesController        homesController = new HomesController(_findProperty);
            var                    requestType     = homesController.GetProperty(Guid.NewGuid());
            BadRequestObjectResult badRequest      = (BadRequestObjectResult)requestType.Result;

            Assert.True(badRequest.StatusCode == 400);
        }
        public void HomesController_GetPropertys_WillReturnThreeValues()
        {
            HomesController       homesController = new HomesController(_findProperty);
            var                   requestType     = homesController.GetProperties();
            OkObjectResult        okRequest       = requestType.Result as OkObjectResult;
            IList <IBaseProperty> results         = okRequest.Value as IList <IBaseProperty>;

            Assert.True(results.Count() == 3);
        }
        public void HomesController_GetPropertyUsingGuid_ReturnPropertyUsingGuid()
        {
            HomesController homesController = new HomesController(_findProperty);
            var             requestType     = homesController.GetProperty(Guid.Parse("6905f139-6705-4ed8-87d7-34b5bc3fb0d6"));
            OkObjectResult  okRequest       = requestType.Result as OkObjectResult;
            IBaseProperty   result          = (IBaseProperty)okRequest.Value;

            Assert.NotNull(result);
        }
Exemplo n.º 15
0
        private void DgvChamCong_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            HomesController homesController = new HomesController();
            DataRowView     row             = dgvChamCong.SelectedItem as DataRowView;

            if (row != null)
            {
                cboTenNhanVien.Text = row.Row.ItemArray[1].ToString();
                dtpNgayLam.Text     = row.Row.ItemArray[2].ToString();
                cboSocalam.Text     = row.Row.ItemArray[3].ToString();
                txtNote.Text        = row.Row.ItemArray[4].ToString();
            }
        }
Exemplo n.º 16
0
        public async Task Put_WhenCalled_ReturnsOkResult()
        {
            var mockedRepo = new Mock <IHomeRepository>();
            var home       = new Home()
            {
                Name = "test_home_1"
            };

            mockedRepo.Setup(repo => repo.EditHome(home)).ReturnsAsync(true);
            var controller = new HomesController(mockedRepo.Object);
            var result     = await controller.Put(home);

            var contentResult = (result as OkObjectResult).Value;

            Assert.NotNull(contentResult);
            Assert.Equal(contentResult, home);
        }
        public void Details_WithInvaidId_ShouldReturnNotFoundResult()
        {
            //Arange
            var homeService = HomeServiceMock.New;

            homeService
            .Setup(hs => hs.Exists(It.IsAny <int>()))
            .Returns(false);

            var controller = new HomesController(homeService.Object, null, null, null, null);

            //Act
            var result = controller.Details(It.IsAny <int>());

            //Asset
            result
            .Should()
            .BeOfType <NotFoundResult>();
        }
Exemplo n.º 18
0
        public async Task Delete_WhenCalled_UnknownObject_ReturnsNotFound()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000002"))).ReturnsAsync((Home)null);

            var result = await controller.Delete("00000000-0000-0000-0000-000000000002");

            var contentResult = result as NotFoundResult;

            Assert.NotNull(contentResult);
        }
Exemplo n.º 19
0
        public async Task Put_WhenCalled_BadObject_ReturnsBadRequest()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            mockedRepo.Setup(repo => repo.EditHome(newHome)).ReturnsAsync(false);

            var result = await controller.Put(newHome);

            var contentResult = result as BadRequestResult;

            Assert.NotNull(contentResult);
        }
Exemplo n.º 20
0
        public async Task Post_WhenCalled_ReturnsOk()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            mockedRepo.Setup(repo => repo.AddHome(newHome)).ReturnsAsync(newHome);

            var result = await controller.Post(newHome);

            var contentResult = (result as OkObjectResult).Value;

            Assert.NotNull(contentResult);
            Assert.Equal(newHome, contentResult);
        }
        private void CboTenNhanVien_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int flag = Convert.ToInt32(taiKhoansController.FindID(cboTenNhanVien.SelectionBoxItem.ToString()));

            if (flag != -1)
            {
                HomesController homesController = new HomesController();
                try
                {
                    var bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.UriSource = new Uri(Environment.CurrentDirectory + @homesController.GetImage(taiKhoansController.FindID(cboTenNhanVien.SelectionBoxItem.ToString())));
                    bitmapImage.EndInit();
                    pctbAvatar.Source = bitmapImage;
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message, "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Exemplo n.º 22
0
        public async Task GetWeather_WhenCalled_UnknownRoom_ReturnsNotFound()
        {
            var mockedRepo = new Mock <IHomeRepository>();
            var home       = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000001")
            };

            var startDate = DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0, 0));
            var endDate   = DateTime.UtcNow;

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync((Home)null);
            mockedRepo.Setup(repo => repo.GetWeather(Guid.Parse("00000000-0000-0000-0000-000000000001"), startDate, endDate)).ReturnsAsync((IEnumerable <Weather>)null);

            var controller = new HomesController(mockedRepo.Object);
            var result     = await controller.GetWeather("00000000-0000-0000-0000-000000000001", startDate, endDate);

            var contentResult = result as NotFoundResult;

            Assert.NotNull(contentResult);
        }
Exemplo n.º 23
0
        public async Task Delete_WhenCalled_DeleteFailed_ReturnsServerError()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync(newHome);
            mockedRepo.Setup(repo => repo.DeleteSensor(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync(false);

            var result = await controller.Delete("00000000-0000-0000-0000-000000000003");

            var contentResult = result as StatusCodeResult;

            Assert.NotNull(contentResult);
            Assert.Equal(StatusCodes.Status500InternalServerError, contentResult.StatusCode);
        }
Exemplo n.º 24
0
        public async Task GetWeather_WhenCalled_MissingQueryParameters_ReturnsBadRequest()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var home = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000001")
            };

            var startDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var endDate   = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            mockedRepo.Setup(repo => repo.GetHome(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(home);
            mockedRepo.Setup(repo => repo.GetWeather(Guid.Parse("00000000-0000-0000-0000-000000000001"), startDate, endDate)).ReturnsAsync((List <Weather>)null);

            var controller = new HomesController(mockedRepo.Object);
            var result     = await controller.GetWeather("00000000-0000-0000-0000-000000000001", startDate, endDate);

            var contentResult = result as BadRequestResult;

            Assert.NotNull(contentResult);
        }