protected void RegisterUser(object sender, EventArgs e) { int roleID = 2; string userName = inputName.Value; string userEmail = inputEmail.Value; string userPassword = inputPassword.Value; string confirmPassword = inputCPassword.Value; string userGender = selectGender.Value; string userStatus = "Active"; Boolean userReady = AuthController.checkExistUser(userName); Boolean boolEmail = (userEmail != null) ? true : false; Boolean boolPass = (userPassword == confirmPassword) ? true : false; if (userReady == false && boolEmail == true && boolPass == true) { CrudController.newUser(roleID, userName, userEmail, userPassword, userGender, userStatus); Response.Redirect("Login.aspx"); } else if (boolPass == false) { errorMsg.Text = "Password tidak sama"; errorMsg.Style.Add("visibility", "visible"); errorMsg.Style.Add("color", "red"); } else { errorMsg.Text = "Email sudah dipakai"; errorMsg.Style.Add("visibility", "visible"); errorMsg.Style.Add("color", "red"); } }
protected void buttonSubmit_Click(object sender, EventArgs e) { string type = inputPaymentType.Value; Boolean paymentAlreadyExist = AuthController.checkPaymentType(type); Boolean boolPaymentType = (type != null) ? true : false; if (paymentAlreadyExist == false && boolPaymentType == true) { CrudController.newPaymentType(type); Response.Redirect("ViewPaymentType.aspx"); } else if (boolPaymentType == false) { errorMsg.Text = "Mohon isi payment type"; errorMsg.Style.Add("visibility", "visible"); errorMsg.Style.Add("color", "red"); } else if (type.Length < 3) { errorMsg.Text = "Payment type harus 3 karakter atau lebih"; errorMsg.Style.Add("visibility", "visible"); errorMsg.Style.Add("color", "red"); } else { errorMsg.Text = "Payment type sudah ada"; errorMsg.Style.Add("visibility", "visible"); errorMsg.Style.Add("color", "red"); } }
protected void updateUser(object sender, EventArgs e) { int id = Int32.Parse(lblUserID.Text); string status = selectStatus.Value; string role = selectRole.Value; CrudController.updateUserA(id, role, status); Response.Redirect("ViewUser.aspx"); }
protected void submitProduct(object sender, EventArgs e) { string productTypeName = inputName.Value; string productTypeDescription = inputDescription.Value; CrudController.insertProductType(productTypeName, productTypeDescription); Response.Redirect("ViewProductType.aspx"); }
protected void updateUser(object sender, EventArgs e) { int id = Int32.Parse(Session["userid"].ToString()); string userEmail = txtEmail.Value; string userName = txtName.Value; string userGender = selectGender.Value; CrudController.updateUser(id, userEmail, userName, userGender); Response.Redirect("ViewProfile.aspx"); }
protected void submitProduct(object sender, EventArgs e) { int id = Int32.Parse(Request.QueryString["ID"]); string productTypeName = inputName.Value; string productTypeDescription = inputDescription.Value; CrudController.updateProductType(id, productTypeName, productTypeDescription); Response.Redirect("ViewProductType.aspx"); }
public void Update_ReturnsModifiedEntity() { var serviceMock = new Mock <ICrudService <TestEntity> >(); var controller = new CrudController <TestEntity>(serviceMock.Object); var actionResult = controller.Update(_entity.Id, _entity); Assert.IsType <OkObjectResult>(actionResult); serviceMock.Verify(_ => _.Update(It.IsAny <Guid>(), It.IsAny <TestEntity>()), Times.Once); }
public async void Delete_ReturnsAsyncOk() { var serviceMock = new Mock <ICrudService <TestEntity> >(); var controller = new CrudController <Guid, TestEntity>(serviceMock.Object); var actionResult = await controller.Delete(_entity.Id); Assert.IsType <OkObjectResult>(actionResult.Result); serviceMock.Verify(_ => _.DeleteAsync(It.IsAny <Guid>()), Times.Once); }
protected void submitProduct(object sender, EventArgs e) { string productName = inputName.Value; int productStock = Int32.Parse(inputStock.Value); int productPrice = Int32.Parse(inputPrice.Value); int productTypeID = Int32.Parse(inputTypeID.Value); CrudController.insertProduct(productName, productStock, productPrice, productTypeID); Response.Redirect("ViewProduct.aspx"); }
protected void submitProduct(object sender, EventArgs e) { int id = Int32.Parse(Request.QueryString["ID"]); string productName = inputName.Value; int productStock = Int32.Parse(inputStock.Value); int productPrice = Int32.Parse(inputPrice.Value); CrudController.submitProduct(id, productName, productStock, productPrice); Response.Redirect("ViewProduct.aspx"); }
public async void Copy_ReturnsNotFound() { var serviceMock = new Mock <ICrudService <TestEntity> >(); serviceMock.Setup(_ => _.CopyAsync(It.IsAny <Guid>())).ThrowsAsync(new EntityNotFoundException()); var controller = new CrudController <Guid, TestEntity>(serviceMock.Object); var actionResult = await controller.Copy(_entity.Id); Assert.IsType <NotFoundResult>(actionResult.Result); serviceMock.Verify(_ => _.CopyAsync(It.IsAny <Guid>()), Times.Once); }
public async void Copy_ReturnsOk() { var serviceMock = new Mock <ICrudService <TestEntity> >(); serviceMock.Setup(_ => _.CopyAsync(It.IsAny <Guid>())).ReturnsAsync(_entity); var controller = new CrudController <Guid, TestEntity>(serviceMock.Object); var actionResult = await controller.Copy(_entity.Id); Assert.IsType <CreatedAtActionResult>(actionResult.Result); serviceMock.Verify(_ => _.CopyAsync(It.IsAny <Guid>()), Times.Once); }
public async void Update_ReturnsAsyncNotFound() { var serviceMock = new Mock <ICrudService <TestEntity> >(); serviceMock.Setup(_ => _.UpdateAsync(It.IsAny <Guid>(), It.IsAny <TestEntity>())).Throws <EntityNotFoundException>(); var controller = new CrudController <Guid, TestEntity>(serviceMock.Object); var actionResult = await controller.Update(_entity.Id, _entity); Assert.IsType <NotFoundResult>(actionResult); serviceMock.Verify(_ => _.UpdateAsync(It.IsAny <Guid>(), It.IsAny <TestEntity>()), Times.Once); }
public void Delete_ReturnsNotFound() { var serviceMock = new Mock <ICrudService <TestEntity> >(); serviceMock.Setup(_ => _.Delete(It.IsAny <Guid>())).Throws <EntityNotFoundException>(); var controller = new CrudController <TestEntity>(serviceMock.Object); var actionResult = controller.Delete(_entity.Id); Assert.IsType <NotFoundResult>(actionResult); serviceMock.Verify(_ => _.Delete(It.IsAny <Guid>()), Times.Once); }
public void GetById_ReturnsNotFound() { var serviceMock = new Mock <ICrudService <TestEntity> >(); serviceMock.Setup(_ => _.GetById(It.IsAny <Guid>())).Throws(new EntityNotFoundException()); var controller = new CrudController <TestEntity>(serviceMock.Object); var actionResult = controller.GetById(Guid.NewGuid()); Assert.IsType <NotFoundResult>(actionResult); serviceMock.Verify(_ => _.GetById(It.IsAny <Guid>()), Times.Once); }
public void CrudController_Index_View_Should_Be_Return_Successfully() { //Assemble CrudController controller = MockRepository.GeneratePartialMock <CrudController>(); //Act ActionResult result = controller.Index(); //Assert Assert.IsNotNull(result); Assert.IsTrue(result is ViewResult); }
public async void HeadById_ReturnsAsyncNoContent() { var id = _entities[0].Id; var serviceMock = new Mock <ICrudService <TestEntity> >(); serviceMock.Setup(_ => _.GetByIdAsync(id)).ReturnsAsync(_entities[0]); var controller = new CrudController <Guid, TestEntity>(serviceMock.Object); var actionResult = await controller.HeadById(id); Assert.IsType <NoContentResult>(actionResult); serviceMock.Verify(_ => _.GetByIdAsync(It.IsAny <Guid>()), Times.Once); }
public void GetAll_ReturnsOk() { var serviceMock = new Mock <ICrudService <TestEntity> >(); serviceMock.Setup(_ => _.GetAll()).Returns(_entities); var controller = new CrudController <TestEntity>(serviceMock.Object); var actionResult = controller.GetAll(); var okResult = actionResult as OkObjectResult; var model = okResult.Value as IEnumerable <TestEntity>; Assert.Equal(model.Count(), _entities.Count); serviceMock.Verify(_ => _.GetAll(), Times.Once); }
public void GetById_ReturnsOk() { var id = _entities[0].Id; var serviceMock = new Mock <ICrudService <TestEntity> >(); serviceMock.Setup(_ => _.GetById(id)).Returns(_entities[0]); var controller = new CrudController <TestEntity>(serviceMock.Object); var actionResult = controller.GetById(id); var okResult = actionResult as OkObjectResult; var model = okResult.Value as TestEntity; Assert.Equal(model.Id, id); serviceMock.Verify(_ => _.GetById(It.IsAny <Guid>()), Times.Once); }
protected void updatePassword(object sender, EventArgs e) { string userPassword = ""; Boolean curr = AuthController.checkExistUserId(Int32.Parse(Session["userid"].ToString()), out userPassword); if (txtNewPassword.Value == txtConfirmPassword.Value && userPassword == txtOldPassword.Value) { string newPassword = txtNewPassword.Value; int id = Int32.Parse(Session["userid"].ToString()); CrudController.updatePassword(id, newPassword); Response.Redirect("ViewProfile.aspx"); } else { } }
protected void deletePaymentType_Click(object sender, EventArgs e) { int id = Int32.Parse(paymentTypeId.Value); Boolean exist = AuthController.checkPaymentTypeId(id); if (exist) { CrudController.removePaymentType(id); viewPaymentType.DataSource = CrudController.getPaymentType(); viewPaymentType.DataBind(); errorMsg.Text = ""; errorMsg.Style.Add("visibility", "hidden"); } else { errorMsg.Text = "Payment Type ID tidak ditemukan"; errorMsg.Style.Add("visibility", "visible"); } }
protected void delProduct(object sender, EventArgs e) { int id = Int32.Parse(productId.Value); Boolean product = AuthController.checkProduct(id); if (product) { CrudController.removeProduct(id); viewProduct.DataSource = CrudController.getProducts(); viewProduct.DataBind(); errorMsg.Text = ""; errorMsg.Style.Add("visibility", "hidden"); } else { errorMsg.Text = "Product ID tidak ditemukan"; errorMsg.Style.Add("visibility", "visible"); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["userrole"].ToString() == "Administrator") { List <User> user = CrudController.getUser(); var dataSource = user.Select(x => new { x.userID, x.userName, x.userStatus, x.Role.roleName }); viewUser.DataSource = dataSource; viewUser.DataBind(); } else { Response.Redirect("Home.aspx"); } }
protected void delProductType(object sender, EventArgs e) { int id = Int32.Parse(productTypeId.Value); Boolean productType = AuthController.checkProductType(id); Boolean product = AuthController.checkProductTypeOnProduct(id); if (productType && !product) { CrudController.removeProductType(id); viewProductType.DataSource = CrudController.getProductType(); viewProductType.DataBind(); errorMsg.Text = ""; errorMsg.Style.Add("visibility", "hidden"); } else { errorMsg.Text = "Gagal delete"; errorMsg.Style.Add("visibility", "visible"); } }
protected void Page_Load(object sender, EventArgs e) { List <ProductType> productType = CrudController.getProductType(); var dataSource = productType.Select(x => new { x.productTypeID, x.productTypeName, x.productTypeDescription }); viewProductType.DataSource = dataSource; viewProductType.DataBind(); if (Session["userrole"].ToString() == "Administrator") { adminPvl.Style.Add("display", "inline"); } else { adminPvl.Style.Add("display", "none"); } }
public CrudControllerFacts(ApiFixture fixture) { this.fixture = fixture; this.controller = this.fixture.ServiceProvider.GetService <CrudController <MockEntity> >(); this.serviceMock = this.fixture.ServiceProvider.GetService <Mock <ICrudService <MockEntity> > >(); }
protected UnitTestCrudController(CrudController<T> crudController) { _crudController = crudController; }
public override void Initialize() { base.Initialize(); RepositoryMock = RepositoriesFactory.GetRepository <TRecordType, TIndexType>() as RepositoryMockBase <TRecordType, TIndexType>; Controller = CreateController(RepositoriesFactory, LoggerMock); }