Exemplo n.º 1
0
        public void Delete_Success()
        {
            // Arrange
            CashDeskItem item = new CashDeskItem()
            {
                Id   = "5c012842f8e2708cf041e247",
                Name = "Caisse_01"
            };
            Acknowledged deleteResult = new Acknowledged(1);

            _cashDeskServicesMock.Setup(x => x.GetCashDesk(item.Id)).Returns(Task.FromResult(item));
            _cashDeskServicesMock.Setup(x => x.DeleteCashDesk(item.Id))
            .ReturnsAsync(deleteResult)
            .Verifiable();
            _cashDeskFlowValidMock
            .Setup(x => x.IsValidOperation(BaseValidatorType.Delete, It.IsAny <CashDeskItem>(), null))
            .Returns(true)
            .Verifiable();

            // Act
            CashDeskController controller   = new CashDeskController(_cashDeskServicesMock.Object, _cashDeskFlowValidMock.Object);
            ActionResult       actionResult = controller.Delete(item.Id);

            // Assert.
            Assert.IsType <NoContentResult>(actionResult);
            NoContentResult actionResultType = actionResult as NoContentResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.NoContent);
            _cashDeskServicesMock.Verify();
            _cashDeskFlowValidMock.Verify();
        }
Exemplo n.º 2
0
        public async Task <bool> UpdateCashDesk(string id, CashDeskItem model)
        {
            if (!ObjectId.TryParse(model.Id, out ObjectId objectId))
            {
                return(false);
            }

            var filter = Builders <Model.CashDeskItem> .Filter.Eq("InternalId", objectId);

            var client = Collection().Find(filter).FirstOrDefaultAsync();

            if (client.Result == null)
            {
                return(false);
            }

            var objectUpdate = Builders <Model.CashDeskItem> .Update
                               .Set(x => x.CurrentState, model.CurrentState)
                               .Set(x => x.CashierName, model.CashierName)
                               .Set(x => x.Update, DateTime.Now);

            await Collection().UpdateOneAsync(filter, objectUpdate);

            return(true);
        }
Exemplo n.º 3
0
        public void Get_All_Success()
        {
            // Arrange
            CashDeskItem item = new CashDeskItem()
            {
                Id   = "5c012842f8e2708cf041e247",
                Name = "Caisse_01"
            };
            IEnumerable <CashDeskItem> items = new List <CashDeskItem>()
            {
                item
            };

            _cashDeskServicesMock.Setup(x => x.GetCashDeskList()).Returns(Task.FromResult(items));

            // Act
            CashDeskController controller   = new CashDeskController(_cashDeskServicesMock.Object, _cashDeskFlowValidMock.Object);
            ActionResult       actionResult = controller.Get().Result;

            // Assert.
            Assert.IsType <OkObjectResult>(actionResult);
            OkObjectResult actionResultType = actionResult as OkObjectResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.Equal(((List <CashDeskItem>)actionResultType.Value), ((List <CashDeskItem>)items.ToList()));
        }
Exemplo n.º 4
0
        public void Put_Success()
        {
            // Arrange
            CashDeskItem item = new CashDeskItem()
            {
                Id   = "5c012842f8e2708cf041e247",
                Name = "Caisse_01"
            };

            _cashDeskServicesMock.Setup(x => x.GetCashDesk(item.Id)).Returns(Task.FromResult(item));
            _cashDeskServicesMock.Setup(x => x.UpdateCashDesk(item.Id, item))
            .ReturnsAsync(true)
            .Verifiable();
            _cashDeskFlowValidMock
            .Setup(x => x.IsValidOperation(BaseValidatorType.Update, It.IsAny <CashDeskItem>(), It.IsAny <CashDeskItem>()))
            .Returns(true)
            .Verifiable();

            // Act
            CashDeskController controller   = new CashDeskController(_cashDeskServicesMock.Object, _cashDeskFlowValidMock.Object);
            ActionResult       actionResult = controller.Put(item);

            // Assert.
            Assert.IsType <AcceptedResult>(actionResult);
            AcceptedResult actionResultType = actionResult as AcceptedResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.Accepted);
            _cashDeskServicesMock.Verify();
            _cashDeskFlowValidMock.Verify();
        }
Exemplo n.º 5
0
        public void Post_Success()
        {
            // Arrange
            CashDeskItem item = new CashDeskItem()
            {
                Id   = "",
                Name = "Caisse_01"
            };

            _cashDeskServicesMock.Setup(x => x.AddCashDesk(item))
            .Verifiable();
            _cashDeskFlowValidMock
            .Setup(x => x.IsValidOperation(BaseValidatorType.Create, It.IsAny <CashDeskItem>(), null))
            .Returns(true)
            .Verifiable();

            // Act
            CashDeskController controller   = new CashDeskController(_cashDeskServicesMock.Object, _cashDeskFlowValidMock.Object);
            ActionResult       actionResult = controller.Post(item);

            // Assert.
            Assert.IsType <CreatedResult>(actionResult);
            CreatedResult actionResultType = actionResult as CreatedResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.Created);
            _cashDeskServicesMock.Verify();
            _cashDeskFlowValidMock.Verify();
        }
Exemplo n.º 6
0
        public void Put_ObjectIdEmpty()
        {
            // Arrange
            CashDeskItem item = new CashDeskItem()
            {
                Id   = "",
                Name = "Caisse_01"
            };

            // Act
            CashDeskController controller   = new CashDeskController(_cashDeskServicesMock.Object, _cashDeskFlowValidMock.Object);
            ActionResult       actionResult = controller.Put(item);

            // Assert.
            Assert.IsType <BadRequestResult>(actionResult);
            BadRequestResult actionResultType = actionResult as BadRequestResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.BadRequest);
        }
Exemplo n.º 7
0
        public ActionResult <CashDeskItem> Get(string id)
        {
            // Validation.
            if ((id == null) ||
                (id.Trim() == string.Empty))
            {
                return(BadRequest());
            }

            // Search Item.
            CashDeskItem cashDeskItem = _iCashDeskServices.GetCashDesk(id).Result;

            if (cashDeskItem == null)
            {
                return(NotFound());
            }

            // Return.
            return(Ok(cashDeskItem));
        }
Exemplo n.º 8
0
        public void Get_Id_IdError()
        {
            // Arrange
            string       fakeId = "this_is_not_a_id";
            CashDeskItem item   = new CashDeskItem()
            {
                Id   = "5c012842f8e2708cf041e247",
                Name = "Caisse_01"
            };

            _cashDeskServicesMock.Setup(x => x.GetCashDesk(item.Id)).Returns(Task.FromResult(item));

            // Act
            CashDeskController controller   = new CashDeskController(_cashDeskServicesMock.Object, _cashDeskFlowValidMock.Object);
            ActionResult       actionResult = controller.Get(fakeId).Result;

            // Assert.
            Assert.IsType <NotFoundResult>(actionResult);
            NotFoundResult actionResultType = actionResult as NotFoundResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.NotFound);
        }
Exemplo n.º 9
0
        public ActionResult Delete(string id)
        {
            // Validation.
            if ((id == null) ||
                (id.Trim() == string.Empty))
            {
                return(BadRequest());
            }

            // Object Flow Validation.
            CashDeskItem cashDeskItem = _iCashDeskServices.GetCashDesk(id).Result;

            if (cashDeskItem == null)
            {
                return(NotFound());
            }
            bool isObjectFlowValid = _iFlowValid.IsValidOperation(BaseValidatorType.Delete, cashDeskItem, null);

            if (!isObjectFlowValid)
            {
                return(BadRequest());
            }

            // Delete.
            MongoDB.Driver.DeleteResult clsDeleteResult = _iCashDeskServices.DeleteCashDesk(id).Result;

            // Return with case.
            if ((clsDeleteResult != null) &&
                (clsDeleteResult.IsAcknowledged) &&
                (clsDeleteResult.DeletedCount > 0))
            {
                return(NoContent());
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 10
0
        public void Get_Id_Success()
        {
            // Arrange
            string       fakeId = "5c012842f8e2708cf041e247";
            CashDeskItem item   = new CashDeskItem()
            {
                Id   = "5c012842f8e2708cf041e247",
                Name = "Caisse_01"
            };

            _cashDeskServicesMock.Setup(x => x.GetCashDesk(item.Id)).Returns(Task.FromResult(item));

            // Act
            CashDeskController controller   = new CashDeskController(_cashDeskServicesMock.Object, _cashDeskFlowValidMock.Object);
            ActionResult       actionResult = controller.Get(fakeId).Result;

            // Assert.
            Assert.IsType <OkObjectResult>(actionResult);
            OkObjectResult actionResultType = actionResult as OkObjectResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.Equal(((CashDeskItem)actionResultType.Value), item);
        }
Exemplo n.º 11
0
        public ActionResult Put([FromBody] CashDeskItem value)
        {
            // Validation.
            if ((value == null) ||
                (value.Id == string.Empty) ||
                (ModelState.IsValid == false))
            {
                return(BadRequest());
            }

            // Object Flow Validation.
            CashDeskItem cashDeskItem = _iCashDeskServices.GetCashDesk(value.Id).Result;

            if (cashDeskItem == null)
            {
                return(NotFound());
            }
            bool isObjectFlowValid = _iFlowValid.IsValidOperation(BaseValidatorType.Update, cashDeskItem, value);

            if (!isObjectFlowValid)
            {
                return(BadRequest());
            }

            // Update.
            bool blnResultUpdate = _iCashDeskServices.UpdateCashDesk(value.Id, value).Result;

            // Return with case.
            if (blnResultUpdate)
            {
                return(Accepted());
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 12
0
        public ActionResult Post([FromBody] CashDeskItem value)
        {
            // Validation.
            if ((value == null) ||
                (value.Id != string.Empty) ||
                (ModelState.IsValid == false))
            {
                return(BadRequest());
            }

            // Object Flow Validation.
            bool isObjectFlowValid = _iFlowValid.IsValidOperation(BaseValidatorType.Create, value, null);

            if (!isObjectFlowValid)
            {
                return(BadRequest());
            }

            // Add.
            _iCashDeskServices.AddCashDesk(value);

            // Return.
            return(Created("GetCashDesk", value));
        }
Exemplo n.º 13
0
 public void AddCashDesk(CashDeskItem model)
 {
     Collection().InsertOne(model);
 }