Ejemplo n.º 1
0
        public void Record(string row)
        {
            List <UserSalesModel>    useSalesCache  = _userSalesCache.Get <List <UserSalesModel> >(DataCacheKey.UserSales);
            UserSalesModel           model          = _csvReader.ReadRow <UserSalesModel>(row);
            IList <ValidationResult> validateResult = ValidateModel(model);

            if (validateResult.Count == 0)
            {
                useSalesCache.Add(model);
                _userSalesCache.Create(useSalesCache, DataCacheKey.UserSales, DataCacheDuration.Medium);
            }
        }
Ejemplo n.º 2
0
        public void ValidateUserSalesModel_Tests()
        {
            var user = new UserSalesModel
            {
                User_Name = "123456789012345678901234567890123456789012345678901",
                Age       = 91,
                Height    = 501,
                Gender    = "Z"
            };

            IList <ValidationResult> validateResult = ValidateModel(user);

            Assert.AreEqual(4, validateResult.Count);
            Assert.IsTrue(ValidateModel(user).Any(
                              v => v.MemberNames.Contains("Gender") &&
                              v.ErrorMessage.Contains("Valid values must be M or F")));
        }
Ejemplo n.º 3
0
        public void CSVReader_ReadRow_Tests(string row)
        {
            ICSVReader csvReader = new CSVReader();

            IEnumerable <string> header = csvReader.GetHeader("user_name,sale_amount,last_purchase_date,age,height,gender");

            csvReader.SetHeader(header);
            UserSalesModel model = csvReader.ReadRow <UserSalesModel>(row);

            Assert.AreEqual(true, csvReader.HasHeader());
            Assert.AreEqual("John Doe", model.User_Name);
            Assert.AreEqual(29, model.Age);
            Assert.AreEqual(177, model.Height);
            Assert.AreEqual("M", model.Gender);
            Assert.AreEqual(21312, model.Sale_Amount);
            Assert.AreEqual(Convert.ToDateTime("2020-11-05T13:15:30Z"), model.Last_Purchase_Date);
        }
Ejemplo n.º 4
0
        public void UserSalesCache_Remove_Test()
        {
            MemoryCacheOptions options   = new MemoryCacheOptions();
            IMemoryCache       cache     = new MemoryCache(options);
            IDataCache         dataCache = new UserSalesCache();

            dataCache.SetCache(cache);
            IUserSales userSales = new UserSalesModel()
            {
                User_Name = "Renel Castro",
            };
            string dateTime = DateTime.Now.ToString("YYYY-MM-dd");

            dataCache.Create(userSales, DataCacheKey.Sales, DataCacheDuration.Short, dateTime);
            dataCache.Remove(DataCacheKey.Sales, dateTime);
            UserSalesModel userSalesCache = dataCache.Get <UserSalesModel>(DataCacheKey.Sales, dateTime);

            Assert.AreEqual(null, userSalesCache.User_Name);
        }