public void EnterExpense()
        {
            var db = new InMemoryDB();
            var personRepository  = new PersonRepository(db);
            var expenseRepository = new ExpenseRepository(db);
            var tripRepository    = new TripRepository(db);

            var personService = new PersonService(personRepository);

            var expenseTracking = new ExpenseTracking(personRepository,
                                                      tripRepository,
                                                      expenseRepository
                                                      );

            var expenseService = new ExpenseService(expenseRepository);

            expenseService.CreateExpense("Lunch", "Lunch");

            var Personlist = personService.CreatePerson(new string[] { "Suresh", "Sakthivel", "Saravanan" });

            var trip = expenseTracking.CreateTrip("trip1", Personlist.Select(p => p.ID));

            expenseTracking.EnterExpense(trip.TripID, 1, new int[] { 2, 3 }, "Lunch", 100);

            var payer = Personlist.Where(p => p.ID == 1).FirstOrDefault();

            var payee = Personlist.Where(p => p.ID != 1).FirstOrDefault();

            Assert.AreEqual(100, payer.AmountToGet());
            Assert.AreEqual(50, payee.AmountToGive());
        }
Esempio n. 2
0
        public HttpResponseMessage Submit([FromBody] MailContract mailContract)
        {
            InMemoryDB imdb = InMemoryDB.Instance;

            imdb.AddMailToDB(mailContract);
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Esempio n. 3
0
        public async Task AddGroupAsync(string groupName)
        {
            await Groups.AddToGroupAsync(Context.ConnectionId, groupName);

            InMemoryDB.AddGroup(groupName, Context.ConnectionId);

            await Clients.All.GroupsAsync(InMemoryDB.GetAllGroups());
        }
Esempio n. 4
0
        public async Task SendMessageToGroupAsync(string message, string groupName)
        {
            groupName = groupName.Trim();

            var senderClient = InMemoryDB.GetClientByConnectionId(Context.ConnectionId);

            await Clients.Groups(groupName).ReceiveMessageAsync(senderClient.NickName, message);
        }
Esempio n. 5
0
        public async Task GetClientsToGroupAsync(string groupName)
        {
            Group group = InMemoryDB.GetGroup(groupName);

            await Clients.Caller.ClientsDataAsync(
                groupName == GroupName
                ?InMemoryDB.GetAllClient()
                    : group.Clients);
        }
Esempio n. 6
0
 public ActionResult Create(User user)
 {
     if (user.FirstName.Length != 0 && user.LastName.Length != 0 && user.EmailAddress.Length != 0)
     {
         user.Id = InMemoryDB.NextId();
         InMemoryDB.Users.Add(user);
     }
     return(RedirectToAction("List"));
 }
Esempio n. 7
0
        private void AddCustomer(InMemoryDB db, int customerId)
        {
            var customer = new SampleCustomerInformation()
            {
                Age        = 10,
                CustomerId = customerId,
                Name       = "Mohsen"
            };

            db.AddCustomer(customer);
        }
Esempio n. 8
0
        public void CreateExpense()
        {
            var db = new InMemoryDB();
            var expenseRepository = new ExpenseRepository(db);

            var expense = new ExpenseService(expenseRepository);

            expense.CreateExpense("BreakFast", "Break Fast");

            var expenseItem = db.ExpenseItems.FirstOrDefault();

            Assert.AreEqual("BreakFast", expenseItem.ExpenseCode);
        }
Esempio n. 9
0
        /// <summary>
        /// Login olan client-in nickName-nin diger userlerde gorunmesinin temin edilmesi
        /// </summary>
        /// <param name="nickName"></param>
        /// <returns></returns>
        public async Task GetNickNameAsync(string nickName)
        {
            InMemoryDB.AddClient(new Client
            {
                ConnectionId = Context.ConnectionId,
                NickName     = nickName
            });


            // Join olan client istisna olmaqla digerlerine Join olanin NickName-nin gosterilmesi
            await Clients.Others.ClientJoinedAsync(nickName);

            // Butun clientlara cari client datalarinin gonderilmesi
            await Clients.All.ClientsDataAsync(InMemoryDB.GetAllClient());
        }
Esempio n. 10
0
        /// <summary>
        /// Clientlar arasinda mesajlasma
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendMessageAsync(string message, string nickName)
        {
            nickName = nickName.Trim();

            var senderClient = InMemoryDB.GetClientByConnectionId(Context.ConnectionId);

            if (nickName == All)
            {
                await Clients.Others.ReceiveMessageAsync(senderClient.NickName, message);
            }
            else
            {
                var receiverClient = InMemoryDB.GetClientByNickName(nickName);
                await Clients.Client(receiverClient.ConnectionId).ReceiveMessageAsync(senderClient.NickName, message);
            }
        }
Esempio n. 11
0
        public void CreatePerson()
        {
            var db = new InMemoryDB();
            var personRepository = new PersonRepository(db);

            var personService = new PersonService(personRepository);

            personService.CreatePerson(new string[] { "Suresh", "Sakthivel" });

            var person = db.Person.FirstOrDefault();

            Assert.AreEqual(1, person.ID);
            Assert.AreEqual("Suresh", person.Name);

            person = db.Person.ElementAt(1);
            Assert.AreEqual(2, person.ID);
            Assert.AreEqual("Sakthivel", person.Name);
        }
Esempio n. 12
0
        public async Task AddClientToGroupsAsync(IEnumerable <string> groupNames)
        {
            Client client = InMemoryDB.GetClientByConnectionId(Context.ConnectionId);

            foreach (var groupName in groupNames)
            {
                Group group = InMemoryDB.GetGroup(groupName);

                var result = group.Clients.Any(i => i.ConnectionId == Context.ConnectionId);
                if (result)
                {
                    continue;
                }
                @group.Clients.Add(client);

                await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
            }
        }
Esempio n. 13
0
        public void AddShardItem_Test()
        {
            ShardConfiguration shardConfiguration = new ShardConfiguration(3);
            IShardKeyAlgorithm shardKeyAlgorithm  = new EvenlyDistributedShardKeyAlgorithm(shardConfiguration);
            InMemoryDB         db = new InMemoryDB(shardConfiguration, shardKeyAlgorithm);

            AddCustomer(db, 1);
            AddCustomer(db, 2);
            AddCustomer(db, 3);
            AddCustomer(db, 4);

            // 3 shards
            var stats = db.GetTotalShardItems();

            Assert.AreEqual(2, stats[0].ItemsCount);
            Assert.AreEqual(1, stats[1].ItemsCount);
            Assert.AreEqual(1, stats[2].ItemsCount);

            // 4 shards
            db.AddShard();
            AddCustomer(db, 5);
            AddCustomer(db, 6);

            stats = db.GetTotalShardItems();
            Assert.AreEqual(3, stats[0].ItemsCount);
            Assert.AreEqual(2, stats[1].ItemsCount);
            Assert.AreEqual(1, stats[2].ItemsCount);

            // 5 shards
            db.AddShard();

            AddCustomer(db, 7);
            AddCustomer(db, 8);
            AddCustomer(db, 9);
            AddCustomer(db, 10);
            AddCustomer(db, 11);

            stats = db.GetTotalShardItems();
            Assert.AreEqual(4, stats[0].ItemsCount);
            Assert.AreEqual(3, stats[1].ItemsCount);
            Assert.AreEqual(2, stats[2].ItemsCount);
            Assert.AreEqual(1, stats[3].ItemsCount);
            Assert.AreEqual(1, stats[4].ItemsCount);
        }
        //test doesn't contains correct relation between dad and child set up in db
        public void SqlServerIntegrationTestWithoutRelation()
        {
            using (var context = new InMemoryDB())
            {
                var service = new Service(context);
                var person  = new Child()
                {
                    Name = "Pawel"
                };

                context.Add(person);
                context.SaveChanges();
            }

            using (var context = new InMemoryDB())
            {
                Assert.AreEqual("Pawel", context.Person.Last().Name);
            }
        }
Esempio n. 15
0
        public void ChangeShardCount_Test()
        {
            ShardConfiguration shardConfiguration = new ShardConfiguration(3);
            IShardKeyAlgorithm shardKeyAlgorithm  = new EvenlyDistributedShardKeyAlgorithm(shardConfiguration);
            InMemoryDB         dataProvider       = new InMemoryDB(shardConfiguration, shardKeyAlgorithm);
            int shardId;

            shardId = dataProvider.GetShardId("1");
            Assert.AreEqual(1, shardId);
            shardId = dataProvider.GetShardId("2");
            Assert.AreEqual(2, shardId);
            shardId = dataProvider.GetShardId("3");
            Assert.AreEqual(3, shardId);
            shardId = dataProvider.GetShardId("4");
            Assert.AreEqual(1, shardId);
            shardId = dataProvider.GetShardId("123");
            Assert.AreEqual(3, shardId);

            // 3 + 1 shards
            dataProvider.AddShard();

            shardId = dataProvider.GetShardId("1");
            Assert.AreEqual(1, shardId);
            shardId = dataProvider.GetShardId("2");
            Assert.AreEqual(2, shardId);
            shardId = dataProvider.GetShardId("3");
            Assert.AreEqual(3, shardId);
            shardId = dataProvider.GetShardId("4");
            Assert.AreEqual(1, shardId);
            shardId = dataProvider.GetShardId("123");
            Assert.AreEqual(3, shardId);
            shardId = dataProvider.GetShardId("5");
            Assert.AreEqual(1, shardId);
            shardId = dataProvider.GetShardId("6");
            Assert.AreEqual(2, shardId);
            shardId = dataProvider.GetShardId("7");
            Assert.AreEqual(3, shardId);
            shardId = dataProvider.GetShardId("8");
            Assert.AreEqual(4, shardId);
        }
Esempio n. 16
0
        public async Task SaveAndRetrieveOne()
        {
            InMemoryDB.ResetInMemoryDatabase();
            InMemoryDB mem      = new InMemoryDB(null);
            ISave      s        = new SaveSqlServer(mem);
            var        response = await File.ReadAllTextAsync(Path.Combine("Data", "20191020bnr.txt"));

            var m = new MockHttpMessageHandler();

            m.When("https://www.bnr.ro/nbrfxrates.xml")
            .Respond("application/text", response);

            var nbr  = new GetNBRExchange(m);
            var data = (await nbr.GetActualRates()).ToArray();
            var nr   = await s.Save(data);

            var f = data[0];
            var q = new RetrieveSqlServer(mem);
            var t = await q.Rate("BNR", f.Date.Date, f.ExchangeFrom);

            Assert.Equal(f.ExchangeValue, t.ExchangeValue);
        }
        //test in memory -  doesn't contains correct relation between dad and child set up in db
        public void WrongSchema()
        {
            var options = new DbContextOptionsBuilder <InMemoryDB>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            using (var context = new InMemoryDB(options, false))
            {
                var service = new Service(context);
                var person  = new Child()
                {
                    Name = "Pawel"
                };

                context.Add(person);
                context.SaveChanges();
            }

            using (var context = new InMemoryDB(options))
            {
                Assert.AreEqual(1, context.Person.Count());
                Assert.AreEqual("Pawel", context.Person.Single().Name);
            }
        }
Esempio n. 18
0
 public HomeController(InMemoryDB context)
 {
     _context = context;
 }