Exemplo n.º 1
0
        public void ApiService_ProcessCreatedObjects_AddTrasaction_TransactionInStorageHasCorrectPayee()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();
            Guid id1 = new Guid("88888888-4444-4444-4444-222222222222");
            Guid id2 = new Guid("88888888-4444-4444-4444-111111111111");

            unitOfWork.StorageContext.People.Add(new Person()
            {
                Id   = id1,
                Name = "Person1"
            });
            unitOfWork.StorageContext.People.Add(new Person()
            {
                Id   = id2,
                Name = "Person2"
            });
            AddTransactionToModel(model, payeesIds: new List <Guid>()
            {
                id1, id2
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Assert.IsNotNull(unitOfWork.StorageContext.Transactions.First().Payees.Where(x => x.Id == id1).First());
        }
Exemplo n.º 2
0
 private void AddTransactionToModel(
     ApiUpdateJsonModel model,
     int id                     = 1,
     decimal amount             = 10,
     string description         = "",
     int groupClientId          = 1,
     Guid groupId               = new Guid(),
     int payerClientId          = 1,
     Guid payerId               = new Guid(),
     List <int> payeesClientIds = null,
     List <Guid> payeesIds      = null
     )
 {
     model.CreatedObjects.Transactions.Add(new JsonTransaction()
     {
         ClientId        = id,
         Amount          = amount,
         Description     = description,
         GroupClientId   = groupClientId,
         GroupId         = groupId,
         PayerClientId   = payerClientId,
         PayerId         = payerId,
         PayeesClientIds = payeesClientIds ?? new List <int>(),
         Payees          = payeesIds ?? new List <Guid>()
     });
 }
Exemplo n.º 3
0
        public void ApiService_ProcessUpdatedObjects_CreateGroupAndUpdatePerson_PersonHasCorrectGroupId()
        {
            IUnitOfWork unitOfWork = Setup();
            Guid        person1Id  = new Guid("88888888-4444-4444-4444-222222222222");
            Guid        group1Id   = new Guid("88888888-1111-4444-4444-222222222222");

            AddGroupToStorage(unitOfWork, group1Id, "group1");
            AddPersonToStorage(unitOfWork, person1Id, "test1", group1Id);

            ApiUpdateJsonModel model = new ApiUpdateJsonModel();

            model.CreatedObjects.Groups.Add(new JsonGroup()
            {
                ClientId = 1,
                Name     = "group2"
            });
            model.UpdatedObjects.People.Add(new JsonPerson()
            {
                Id            = person1Id,
                Name          = "test2",
                GroupClientId = 1
            });

            ApiService apiService = new ApiService(unitOfWork, model);

            ApiUpdateJsonReturnModel returnModel = apiService.ProcessCreatedObjects();

            apiService.ProcessUpdatedObjects();

            Guid createdGroupId = returnModel.AddedGroups.First().Id;

            Assert.AreEqual(createdGroupId, unitOfWork.StorageContext.People.First().GroupId);
        }
Exemplo n.º 4
0
        public void ApiService_ProcessCreatedObjects_AddTransactionWithCientIds_TransactionInStorageHas2Payees()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();
            int id1 = 1;
            int id2 = 2;

            model.CreatedObjects.People.Add(new JsonPerson()
            {
                ClientId = id1
            });
            model.CreatedObjects.People.Add(new JsonPerson()
            {
                ClientId = id2
            });
            AddTransactionToModel(model, payeesClientIds: new List <int>()
            {
                id1, id2
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Assert.AreEqual(2, unitOfWork.StorageContext.Transactions.First().Payees.Count);
        }
Exemplo n.º 5
0
        public void ApiService_ProcessCreatedObjects_AddTransactionWithCientIds_TransactionInStorageHasCorrectPayeeId()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();
            int id1 = 1;
            int id2 = 2;

            model.CreatedObjects.People.Add(new JsonPerson()
            {
                ClientId = id1
            });
            model.CreatedObjects.People.Add(new JsonPerson()
            {
                ClientId = id2
            });
            AddTransactionToModel(model, payeesClientIds: new List <int>()
            {
                id1, id2
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Guid payeeId = unitOfWork.StorageContext.People.First().Id;

            Assert.IsNotNull(unitOfWork.StorageContext.Transactions.First().Payees.Where(x => x.Id == payeeId).First());
        }
Exemplo n.º 6
0
        public void ApiService_ProcessUpdatedObjects_CreatePersonAndUpdateTransaction_TransactionHasCorrectPayerId()
        {
            IUnitOfWork unitOfWork     = Setup();
            Guid        transaction1Id = new Guid("88888888-4444-4444-4444-222222222222");
            Guid        person1Id      = new Guid("88888888-1111-4444-4444-222222222222");

            AddPersonToStorage(unitOfWork, person1Id, "person1", Guid.Empty);
            AddTransactionIntoStorage(unitOfWork, transaction1Id, 10, payerId: person1Id);

            ApiUpdateJsonModel model = new ApiUpdateJsonModel();

            model.CreatedObjects.People.Add(new JsonPerson()
            {
                ClientId = 1,
                Name     = "person2"
            });
            model.UpdatedObjects.Transactions.Add(new JsonTransaction()
            {
                Id            = transaction1Id,
                PayerClientId = 1
            });

            ApiService apiService = new ApiService(unitOfWork, model);

            ApiUpdateJsonReturnModel returnModel = apiService.ProcessCreatedObjects();

            apiService.ProcessUpdatedObjects();

            Guid createdPersonId = returnModel.AddedPeople.First().Id;

            Assert.AreEqual(createdPersonId, unitOfWork.StorageContext.Transactions.First().PayerId);
        }
Exemplo n.º 7
0
        public void ApiService_ProcessUpdatedObjects_UpdatePersonsGroup_GroupIsUpdated()
        {
            IUnitOfWork unitOfWork = Setup();
            Guid        personId   = new Guid("88888888-4444-4444-4444-222222222222");
            Guid        group1Id   = new Guid("88888888-1111-4444-4444-222222222222");
            Guid        group2Id   = new Guid("88888888-2222-4444-4444-222222222222");

            AddGroupToStorage(unitOfWork, group1Id, "group1");
            AddGroupToStorage(unitOfWork, group2Id, "group2");
            AddPersonToStorage(unitOfWork, personId, "test1", group1Id);

            ApiUpdateJsonModel model = new ApiUpdateJsonModel();

            model.UpdatedObjects.People.Add(new JsonPerson()
            {
                Id      = personId,
                Name    = "test2",
                GroupId = group2Id
            });

            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessUpdatedObjects();

            Assert.AreEqual(group2Id, unitOfWork.StorageContext.People.First().GroupId);
        }
Exemplo n.º 8
0
        public void ApiService_ProcessUpdatedObjects_CreatePersonAndUpdateTransaction_TransactionHasPayeeCountOf1()
        {
            IUnitOfWork unitOfWork     = Setup();
            Guid        transaction1Id = new Guid("88888888-4444-4444-4444-222222222222");
            Guid        person1Id      = new Guid("88888888-1111-4444-4444-222222222222");

            AddPersonToStorage(unitOfWork, person1Id, "person1", Guid.Empty);
            AddTransactionIntoStorage(unitOfWork, transaction1Id, 10, payeeIds: new HashSet <Person>()
            {
                unitOfWork.StorageContext.People.First()
            });

            ApiUpdateJsonModel model = new ApiUpdateJsonModel();

            model.CreatedObjects.People.Add(new JsonPerson()
            {
                ClientId = 1,
                Name     = "person2"
            });
            model.UpdatedObjects.Transactions.Add(new JsonTransaction()
            {
                Id = transaction1Id,
                PayeesClientIds = new List <int>()
                {
                    1
                }
            });

            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();
            apiService.ProcessUpdatedObjects();

            Assert.AreEqual(1, unitOfWork.StorageContext.Transactions.First().Payees.Count);
        }
Exemplo n.º 9
0
        public void ApiService_ProcessCreatedObjects_AddPeopleWithGroupId_GroupIdSaved()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();

            model.CreatedObjects.Groups.Add(new JsonGroup()
            {
                ClientId = 2,
                Name     = "Group1"
            });
            model.CreatedObjects.People.Add(new JsonPerson()
            {
                GroupClientId = 2,
                Name          = "Person1"
            });

            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Group  group  = unitOfWork.StorageContext.Groups.First();
            Person person = unitOfWork.StorageContext.People.First();

            Assert.AreEqual(group.Id, person.GroupId);
        }
Exemplo n.º 10
0
        public void ApiService_ProcessUpdatedObjects_CreateGroupAndUpdateTransaction_TransactionHasCorrectGroupId()
        {
            IUnitOfWork unitOfWork     = Setup();
            Guid        transaction1Id = new Guid("88888888-4444-4444-4444-222222222222");
            Guid        group1Id       = new Guid("88888888-1111-4444-4444-222222222222");

            AddGroupToStorage(unitOfWork, group1Id, "group1");
            AddTransactionIntoStorage(unitOfWork, transaction1Id, 10, group1Id);

            ApiUpdateJsonModel model = new ApiUpdateJsonModel();

            model.CreatedObjects.Groups.Add(new JsonGroup()
            {
                ClientId = 1,
                Name     = "group2"
            });
            model.UpdatedObjects.Transactions.Add(new JsonTransaction()
            {
                Id            = transaction1Id,
                GroupClientId = 1
            });

            ApiService apiService = new ApiService(unitOfWork, model);

            ApiUpdateJsonReturnModel returnModel = apiService.ProcessCreatedObjects();

            apiService.ProcessUpdatedObjects();

            Guid createdGroupId = returnModel.AddedGroups.First().Id;

            Assert.AreEqual(createdGroupId, unitOfWork.StorageContext.Transactions.First().GroupId);
        }
Exemplo n.º 11
0
        // GET api/<controller>
        //public IEnumerable<string> Get()
        //{
        //  return new string[] { "value1", "value2" };
        //}

        // GET api/<controller>/5
        //public string Get(int id)
        //{
        //  return "value";
        //}

        // POST api/<controller>
        public ApiUpdateJsonReturnModel Sync([FromBody] ApiUpdateJsonModel model)
        {
            ApiService apiService = new ApiService(_unitOfWork, model);

            ApiUpdateJsonReturnModel returnModel = apiService.ProcessCreatedObjects();

            apiService.ProcessUpdatedObjects();

            return(returnModel);
        }
Exemplo n.º 12
0
        public void ApiService_ProcessCreatedObjects_AddTrasaction_TransactionInStorageHasCorrectAmount()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();

            AddTransactionToModel(model, amount: 10);
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Assert.AreEqual(10, unitOfWork.StorageContext.Transactions.First().Amount);
        }
Exemplo n.º 13
0
        public void ApiService_ProcessCreatedObjects_AddTrasaction_TransactionAddedToStorage()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();

            AddTransactionToModel(model);
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Assert.AreEqual(1, unitOfWork.StorageContext.Transactions.Count());
        }
Exemplo n.º 14
0
        public void ApiService_ProcessCreatedObjects_AddTrasaction_TransactionInStorageHasCorrectDescription()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();

            AddTransactionToModel(model, description: "test");
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Assert.AreEqual("test", unitOfWork.StorageContext.Transactions.First().Description);
        }
Exemplo n.º 15
0
        public void ApiService_ProcessCreatedObjects_AddTransaction_NewIdAddedToReturnModel()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();

            AddTransactionToModel(model);

            ApiService apiService = new ApiService(unitOfWork, model);

            var returnedModel = apiService.ProcessCreatedObjects();

            Assert.AreEqual(1, returnedModel.AddedTransactions.Count);
        }
Exemplo n.º 16
0
        public void ApiService_ProcessCreatedObjects_ModelWithTwoGroup_GroupsAddedToStorage()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = SetupGroupsForAdd(new List <string>()
            {
                "one", "two"
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Assert.AreEqual(unitOfWork.StorageContext.Groups.Count(), 2);
        }
Exemplo n.º 17
0
        public void ApiService_ProcessCreatedObjects_Add2Groups_ReturnedObjectGroupCountIs2()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = SetupGroupsForAdd(new List <string>()
            {
                "test1", "test2"
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            ApiUpdateJsonReturnModel returnModel = apiService.ProcessCreatedObjects();

            Assert.AreEqual(2, returnModel.AddedGroups.Count);
        }
Exemplo n.º 18
0
        public void ApiService_ProcessCreatedObjects_Add2Peple_2ndPersonAddedToReturnModel()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = SetupPeopleForAdd(new List <string>()
            {
                "test1", "test2"
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            ApiUpdateJsonReturnModel returnModel = apiService.ProcessCreatedObjects();

            Assert.AreEqual(unitOfWork.StorageContext.People.Skip(1).First().Id, returnModel.AddedPeople.Skip(1).First().Id);
        }
Exemplo n.º 19
0
        public void ApiService_ProcessCreatedObjects_ModelWithTwoPeople_PeopleStorageCountEquals2()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = SetupPeopleForAdd(new List <string>()
            {
                "one", "two"
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Assert.AreEqual(unitOfWork.StorageContext.People.Count(), 2);
        }
Exemplo n.º 20
0
        public void ApiService_ProcessCreatedObjects_AddGroup_ReturnedObjectContaineNewGroupId()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = SetupGroupsForAdd(new List <string>()
            {
                "test1"
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            ApiUpdateJsonReturnModel returnModel = apiService.ProcessCreatedObjects();

            Assert.AreEqual(unitOfWork.StorageContext.Groups.First().Id, returnModel.AddedGroups.First().Id);
        }
Exemplo n.º 21
0
        private ApiUpdateJsonModel SetupGroupsForAdd(List <string> names)
        {
            ApiUpdateJsonModel model = new ApiUpdateJsonModel();

            foreach (string name in names)
            {
                model.CreatedObjects.Groups.Add(new JsonGroup()
                {
                    Name = name
                });
            }
            return(model);
        }
Exemplo n.º 22
0
        private ApiUpdateJsonModel SetupPeopleForAdd(List <string> names)
        {
            ApiUpdateJsonModel model = new ApiUpdateJsonModel();

            foreach (string name in names)
            {
                model.CreatedObjects.People.Add(new JsonPerson()
                {
                    Name = name,
                });
            }
            return(model);
        }
Exemplo n.º 23
0
        public void ApiService_ProcessCreatedObjects_AddTrasaction_TransactionInStorageHasCorrectPayerId()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();
            Guid payerId = Guid.NewGuid();

            AddTransactionToModel(model, payerId: payerId);
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Assert.AreEqual(payerId, unitOfWork.StorageContext.Transactions.First().PayerId);
        }
Exemplo n.º 24
0
        public void ApiService_ProcessCreatedObjects_AddGroup_CreatedIdInReturnedObject()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = SetupGroupsForAdd(new List <string>()
            {
                "test1"
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            ApiUpdateJsonReturnModel returnModel = apiService.ProcessCreatedObjects();

            Assert.IsNotNull(returnModel.AddedGroups.First().Id);
        }
Exemplo n.º 25
0
        public ApiService(IUnitOfWork unitOfWork, ApiUpdateJsonModel model)
        {
            _unitOfWork         = unitOfWork;
            _groupService       = new GroupService(_unitOfWork);
            _personService      = new PersonService(_unitOfWork);
            _transactionService = new TransactionService(_unitOfWork);

            _model             = model;
            _addedGroups       = new List <AddedEntity <Group> >();
            _addedPeople       = new List <AddedEntity <Person> >();
            _addedTransactions = new List <AddedEntity <Transaction> >();
            _returnModel       = new ApiUpdateJsonReturnModel();
        }
Exemplo n.º 26
0
        public void ApiService_ProcessCreatedObjects_AddGroupWithName_NameOfGroupIsSaved()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = SetupGroupsForAdd(new List <string>()
            {
                "test"
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Assert.AreEqual(unitOfWork.StorageContext.Groups.First().Name, "test");
        }
Exemplo n.º 27
0
        public void ApiService_ProcessCreatedObjects_AddPeopleWithNames_NamesOfPeopleAreSaved()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = SetupPeopleForAdd(new List <string>()
            {
                "test1", "test2"
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Person person = unitOfWork.StorageContext.People.Skip(1).FirstOrDefault();

            Assert.AreEqual(person.Name, "test2");
        }
Exemplo n.º 28
0
        public void ApiService_ProcessCreatedObjects_AddTwoGroupsWithNames_NamesOfGroupsAreSaved()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = SetupGroupsForAdd(new List <string>()
            {
                "test1", "test2"
            });
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Group group = unitOfWork.StorageContext.Groups.Where(x => string.Equals(x.Name, "test2")).FirstOrDefault();

            Assert.AreEqual(group.Name, "test2");
        }
Exemplo n.º 29
0
        public void ApiService_ProcessUpdatedObjects_NullUpdatedObjects_DoesNotError()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();

            model.UpdatedObjects = null;
            ApiService apiService = new ApiService(unitOfWork, model);

            try
            {
                apiService.ProcessUpdatedObjects();
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }
Exemplo n.º 30
0
        public void ApiService_ProcessCreatedObjects_AddTransactionWithPayerCientIds_TransactionInStorageHasCorrectPayerId()
        {
            IUnitOfWork        unitOfWork = Setup();
            ApiUpdateJsonModel model      = new ApiUpdateJsonModel();
            int id1 = 1;

            model.CreatedObjects.People.Add(new JsonPerson()
            {
                ClientId = id1
            });
            AddTransactionToModel(model, payerClientId: id1);
            ApiService apiService = new ApiService(unitOfWork, model);

            apiService.ProcessCreatedObjects();

            Guid payerId = unitOfWork.StorageContext.People.First().Id;

            Assert.AreEqual(unitOfWork.StorageContext.Transactions.First().PayerId, payerId);
        }