Exemple #1
0
        public void EqualsCore_RulesMustBeEquals_False()
        {
            // Arrange
            RuleHoliday ruleA, ruleB;

            // Act
            ruleA = RuleHoliday.CreateRuleHoliday(null, EntityStatus.Locked, ActionType.Update, Guid.Parse("41408960-a65f-42ea-93c0-e320a1bc7060"), Guid.Parse("41408960-a65f-42ea-93c0-e320a1bc7060"), Guid.Parse("41408960-a65f-42ea-93c0-e320a1bc7070"), "USA", null, "", "", HolidayType.National, "Bennington Battle Day", "Bennington Battle Day", 8, 16, false, "", "16 August or nearest weekday");
            ruleB = RuleHoliday.CreateRuleHoliday(null, EntityStatus.Locked, ActionType.Update, Guid.Parse("41408960-a65f-42ea-93c0-e320a1bc7060"), Guid.Parse("41408960-a65f-42ea-93c0-e320a1bc7060"), Guid.Parse("41408960-a65f-42ea-93c0-e320a1bc7070"), "USA", null, "", "", HolidayType.Local, "Bennington Battle Day", "Bennington Battle Day", 8, 16, false, "", "16 August or nearest weekday");

            // Assert
            Assert.NotEqual(ruleA, ruleB);
            Assert.True(ruleA != ruleB);
        }
Exemple #2
0
        public void CreateRule_MustCreateInstaceOfRule(string id, string status, string typeProcess, string user, string country, string state, string countryIsoCode, string stateIsoCode, string cityCode, string cityName, string holidayType, string nativeHolidayName, string englishHolidayName, int month, int day, bool optional, string bussinessRule, string comments)
        {
            // Arrange
            RuleHoliday  ruleHoliday;
            Guid         entityId     = string.IsNullOrEmpty(id) ? Guid.Empty : Guid.Parse(id);
            EntityStatus entityStatus = EntityStatus.GetByName(status);
            ActionType   action       = ActionType.GetByName(typeProcess);
            HolidayType  type         = HolidayType.GetByName(holidayType);
            Guid         userId       = string.IsNullOrEmpty(user) ? Guid.Empty : Guid.Parse(user);
            Guid         countryId    = string.IsNullOrEmpty(country) ? Guid.Empty : Guid.Parse(country);
            Guid         stateId      = string.IsNullOrEmpty(state) ? Guid.Empty : Guid.Parse(state);

            // Act
            ruleHoliday = RuleHoliday.CreateRuleHoliday(entityId, entityStatus, action, userId, countryId, stateId, countryIsoCode, stateIsoCode, cityCode, cityName, type, nativeHolidayName, englishHolidayName, month, day, optional, bussinessRule, comments);

            // Assert
            Assert.NotNull(ruleHoliday);
            Assert.True(ruleHoliday.Id != entityId &&
                        ruleHoliday.Status == entityStatus &&
                        ruleHoliday.Action == action &&
                        (ruleHoliday.RegisteredBy == userId || ruleHoliday.ModifiedBy == userId) &&
                        ruleHoliday.CountryId == countryId &&
                        ruleHoliday.StateId == stateId &&
                        ruleHoliday.CountryIsoCode == countryIsoCode &&
                        ruleHoliday.StateIsoCode == stateIsoCode &&
                        ruleHoliday.CityCode == cityCode &&
                        ruleHoliday.CityName == cityName &&
                        ruleHoliday.HolidayType == type &&
                        ruleHoliday.NativeHolidayName == nativeHolidayName &&
                        ruleHoliday.EnglishHolidayName == englishHolidayName &&
                        (ruleHoliday.Month == month || ruleHoliday.Month == null) &&
                        (ruleHoliday.Day == day || ruleHoliday.Day == null) &&
                        ruleHoliday.Optional == optional &&
                        ruleHoliday.BussinessRule == bussinessRule.Replace(" ", "").Trim().ToLower() &&
                        ruleHoliday.Comments == comments);
        }
        private static async Task <List <RuleHoliday> > GetRulesHolidaysFromCsvAsync(string[,] rulesHolidaysCsv, int start, int end, ICountryRepository countryRepository, IStateRepository stateRepository, IUserLogged userLogged)
        {
            List <RuleHoliday> rules = null;

            if (rulesHolidaysCsv != null && rulesHolidaysCsv.GetLength(0) > 0)
            {
                rules = new List <RuleHoliday>();

                try
                {
                    Guid    userId            = userLogged.GetUserId();
                    Guid    countryId         = Guid.Empty;
                    Guid?   stateId           = null;
                    Country country           = null;
                    string  stateCodePrevious = "?";

                    for (int i = start, j = end; i < j; i++)
                    {
                        var id                     = rulesHolidaysCsv[i, 0].HasValue() ? int.Parse((rulesHolidaysCsv[i, 0]).Trim()) : -1;
                        var countryCode            = rulesHolidaysCsv[i, 1].Trim();
                        var stateName              = rulesHolidaysCsv[i, 2].Trim();
                        var stateCode              = rulesHolidaysCsv[i, 3].Trim();
                        var month                  = rulesHolidaysCsv[i, 4].ToMonth();
                        var day                    = rulesHolidaysCsv[i, 5].ToDay();
                        var nativeDescription      = rulesHolidaysCsv[i, 6].Trim();
                        var alternativeDescription = rulesHolidaysCsv[i, 7].Trim();
                        var holidayType            = rulesHolidaysCsv[i, 8].Replace("  ", " ").Trim();
                        var cityName               = rulesHolidaysCsv[i, 9].Trim();
                        var cityCode               = rulesHolidaysCsv[i, 10].Trim();
                        var optional               = rulesHolidaysCsv[i, 11].HasValue();
                        var bussinessRule          = rulesHolidaysCsv[i, 12].ToLower().Trim().Replace(" ", "");
                        var comments               = rulesHolidaysCsv[i, 13].Trim();

                        if (country == null || country.CountryIsoCode3 != countryCode)
                        {
                            country   = (await countryRepository.FindAsync(c => c.CountryIsoCode3 == countryCode)).FirstOrDefault();
                            countryId = country != null ? country.Id : Guid.Empty;
                        }

                        if (stateCode.HasValue() && stateCode != stateCodePrevious)
                        {
                            stateCodePrevious = stateCode;
                            stateId           = await SetStateIdAsync(stateRepository, stateCode, countryCode);
                        }

                        HolidayType type = SetHolidayType(holidayType, cityName, stateCode);

                        comments = SetComments(holidayType, comments);

                        var ruleHoliday = RuleHoliday.CreateRuleHoliday(null, EntityStatus.Active, ActionType.Register, userId, countryId, stateId, countryCode, stateCode, cityCode, cityName, type, nativeDescription, alternativeDescription, month, day, optional, bussinessRule, comments);

                        rules.Add(ruleHoliday);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(rules);
        }