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

                string attachedObjectText = addedNotes.ToString();
                Notes newNotes = JsonConvert.DeserializeObject <Notes>(attachedObjectText);
                AddNotesRequest addNotesRequest = new AddNotesRequest(newNotes.Topic, newNotes.Text, newNotes.Date, newNotes.Image, newNotes.IdAccount);

                try
                {
                    AddNotesResponse addNotesResponse = hubController.UseCaseFactory.CreateAddNotesUseCase().Execute(addNotesRequest);
                    List <NotesDTO> notesDTO = hubController.TransformNotes(addNotesResponse.Notes);
                    operationStatusInfo.AttachedObject = notesDTO;
                    operationStatusInfo.AttachedInfo = "Notes are added!";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Ejemplo n.º 2
0
        public void AddNotesUseCaseEqualTest()
        {
            AddNotesRequest addNotesRequest = new AddNotesRequest(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);
            AddNotesResponse addNotesResponse = useCaseFactory.CreateAddNotesUseCase().Execute(addNotesRequest);

            Assert.AreEqual(addNotesResponse.Notes[2].Topic, topic);
            Assert.AreEqual(addNotesResponse.Notes[2].Text, text);
            Assert.AreEqual(addNotesResponse.Notes[2].Date, date);
            Assert.AreEqual(addNotesResponse.Notes[2].Image, image);
        }