Ejemplo n.º 1
0
        public async Task <OperationStatusInfo> UpdateNotes(object updatedNotes)
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);

                string attachedObjectText = updatedNotes.ToString();
                Notes newNotes = JsonConvert.DeserializeObject <Notes>(attachedObjectText);
                EditNotesRequest editNotesRequest = new EditNotesRequest(newNotes.Id, newNotes.Topic, newNotes.Text, newNotes.Date, newNotes.Image, newNotes.IdAccount);

                try
                {
                    EditNotesResponse editNotesResponse = hubController.UseCaseFactory.CreateEditNotesUseCase().Execute(editNotesRequest);
                    List <NotesDTO> notesDTO = hubController.TransformNotes(editNotesResponse.Notes);
                    operationStatusInfo.AttachedObject = notesDTO;
                    operationStatusInfo.AttachedInfo = "Notes are updated!";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Ejemplo n.º 2
0
        public void EditNotesUseCaseEqualTest()
        {
            EditNotesRequest editNotesRequest = new EditNotesRequest(id, topic, text, date, image, idAccount);

            IUnitOfWorkFactory unitOfWorkFactory = new UnitOfWorkFactory();
            IUnitOfWork        unitOfWork        = unitOfWorkFactory.CreateUnitOfWork();

            unitOfWork.GetNotesFromDatabase();
            IActivityFactory  activityFactory   = new ActivityFactory(unitOfWork, new ValidationRuleFactory());
            IUseCaseFactory   useCaseFactory    = new UseCaseFactory(activityFactory);
            EditNotesResponse editNotesResponse = useCaseFactory.CreateEditNotesUseCase().Execute(editNotesRequest);

            Assert.AreEqual(editNotesResponse.Notes[0].Topic, topic);
            Assert.AreEqual(editNotesResponse.Notes[0].Text, text);
            Assert.AreEqual(editNotesResponse.Notes[0].Date, date);
            Assert.AreEqual(editNotesResponse.Notes[0].Image, image);
        }
Ejemplo n.º 3
0
        public void EditNotesUseCaseNotEqualTest()
        {
            Exception exception = null;

            try
            {
                EditNotesRequest editNotesRequest = new EditNotesRequest(10, topic, text, date, image, idAccount);

                IUnitOfWorkFactory unitOfWorkFactory = new UnitOfWorkFactory();
                IUnitOfWork        unitOfWork        = unitOfWorkFactory.CreateUnitOfWork();
                unitOfWork.GetNotesFromDatabase();
                IActivityFactory  activityFactory   = new ActivityFactory(unitOfWork, new ValidationRuleFactory());
                IUseCaseFactory   useCaseFactory    = new UseCaseFactory(activityFactory);
                EditNotesResponse editNotesResponse = useCaseFactory.CreateEditNotesUseCase().Execute(editNotesRequest);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.AreEqual(exception.Message, "The notes are not updated and not found!");
        }