Esempio n. 1
0
        public async Task CommanderVersionControllerTestCreateVersion_FailInvalidFormat()
        {
            MockCommanderVersionRepository api = new MockCommanderVersionRepository();
            IDistributedCache   _cache         = FakeCache();
            IOptions <Settings> appSettings    = Substitute.For <IOptions <Settings> >();
            var localizer = new MockStringLocalizer <CommanderVersionController>();

            localizer[0] = new LocalizedString("CommanderCreateversionsVersionFormatErrorMsg", "Invalid Version format");
            ICommanderVersionApi       commanderVersionApi = new CommanderVersionApi(appSettings, api);
            CommanderVersionController controller          = FakeController(_cache, commanderVersionApi, localizer);

            Wp.CIS.LynkSystems.Model.CommanderVersion commanderVersion = new Wp.CIS.LynkSystems.Model.CommanderVersion()
            {
                BaseVersionID      = null,
                VersionDescription = "test 123"
            };
            //.. Act

            var dinfo = await controller.CreateVersion(commanderVersion);

            var actualRecord = (Microsoft.AspNetCore.Mvc.ObjectResult)dinfo;

            //..Assert
            Assert.Equal(actualRecord.StatusCode, (int)System.Net.HttpStatusCode.BadRequest);
            Assert.Equal(actualRecord.Value, "Invalid Version format");
        }
Esempio n. 2
0
        public async Task CommanderVersionControllerTestCreateVersion_Pattern2Success()
        {
            MockCommanderVersionRepository api             = new MockCommanderVersionRepository();
            IDistributedCache          _cache              = FakeCache();
            IOptions <Settings>        appSettings         = Substitute.For <IOptions <Settings> >();
            ICommanderVersionApi       commanderVersionApi = new CommanderVersionApi(appSettings, api);
            CommanderVersionController controller          = FakeController(_cache, commanderVersionApi);

            Wp.CIS.LynkSystems.Model.CommanderVersion commanderVersion = new Wp.CIS.LynkSystems.Model.CommanderVersion()
            {
                BaseVersionID      = null,
                VersionDescription = "WPYPAK 6.02.06",
                CreatedByUser      = "******"
            };
            //.. Act

            var dinfo = await controller.CreateVersion(commanderVersion);

            var actualRecord   = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value;
            int newVersionId   = api.versionInfo.Max(s => Convert.ToInt32(s.VersionID));
            var currentVersion = api.versionInfo.Where(s => Convert.ToInt32(s.VersionID) == newVersionId).FirstOrDefault();

            //..Assert
            Assert.Equal(((bool)actualRecord), true);
            Assert.Equal(commanderVersion, currentVersion);
        }
Esempio n. 3
0
        public async Task CommanderVersionControllerTestCreateVersion_BaseVersionFail()
        {
            MockCommanderVersionRepository api = new MockCommanderVersionRepository();
            IDistributedCache   _cache         = FakeCache();
            IOptions <Settings> appSettings    = Substitute.For <IOptions <Settings> >();

            var localizer = new MockStringLocalizer <CommanderVersionController>();

            localizer[0] = new LocalizedString("CommanderCreateversionsErrorMsg", "Base version not exists");
            ICommanderVersionApi       commanderVersionApi = new CommanderVersionApi(appSettings, api);
            CommanderVersionController controller          = FakeController(_cache, commanderVersionApi, localizer);


            Wp.CIS.LynkSystems.Model.CommanderVersion commanderVersion = new Wp.CIS.LynkSystems.Model.CommanderVersion()
            {
                BaseVersionID      = 1000,
                VersionDescription = "WPYPAK 6.02.08",
                CreatedByUser      = "******"
            };
            //.. Act

            var dinfo = await controller.CreateVersion(commanderVersion);

            var actualRecord = (Microsoft.AspNetCore.Mvc.ObjectResult)dinfo;

            //..Assert
            Assert.Equal(actualRecord.StatusCode, (int)System.Net.HttpStatusCode.InternalServerError);
            Assert.Equal((actualRecord.Value), "Base version not exists");
        }
Esempio n. 4
0
        public Task <bool> CreateVersionAsync(Wp.CIS.LynkSystems.Model.CommanderVersion commanderVersion)
        {
            if (versionInfo.Any(s => s.VersionDescription == commanderVersion.VersionDescription))
            {
                throw new Exception("Same version already exists");
            }
            if (!ValidateVersionFormat(commanderVersion.VersionDescription))
            {
                throw new Exception("Invalid version format");
            }
            if (commanderVersion.BaseVersionID.HasValue)
            {
                if (!versionInfo.Any(s => Convert.ToInt32(s.VersionID) == commanderVersion.BaseVersionID))
                {
                    throw new Exception("Base version not exists");
                }
            }
            int newVersionId = versionInfo.Max(s => Convert.ToInt32(s.VersionID)) + 1;

            commanderVersion.VersionID = Convert.ToString(newVersionId);
            versionInfo.Add(commanderVersion);
            if (commanderVersion.BaseVersionID.HasValue)
            {
                var mapping = (EPSMapping)MockUtility.CloneObject(epsMapping.Where(s => s.versionID == commanderVersion.BaseVersionID.Value).FirstOrDefault());
                mapping.versionID = newVersionId;
                epsMapping.Add(mapping);

                var table = (PetroTable)MockUtility.CloneObject(petroTable.Where(s => s.VersionID == commanderVersion.BaseVersionID.Value).FirstOrDefault());
                table.VersionID = newVersionId;
                petroTable.Add(table);
            }
            return(Task.Run(() => true));
        }
Esempio n. 5
0
        public async Task <bool> CreateVersionAsync(Wp.CIS.LynkSystems.Model.CommanderVersion commanderVersion)
        {
            try
            {
                var p = new DynamicParameters();
                p.Add("VersionDescription", commanderVersion.VersionDescription, DbType.String);
                p.Add("BaseVersionID", commanderVersion.BaseVersionID, DbType.Int32);
                p.Add("CreatedByUser", commanderVersion.CreatedByUser, DbType.String);
                var result = await CreateVersion(p);

                return(await Task.FromResult(result));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Esempio n. 6
0
        public async Task CommanderVersionControllerTestCreateVersion_BaseVersionSuccess()
        {
            MockCommanderVersionRepository api             = new MockCommanderVersionRepository();
            IDistributedCache          _cache              = FakeCache();
            IOptions <Settings>        appSettings         = Substitute.For <IOptions <Settings> >();
            ICommanderVersionApi       commanderVersionApi = new CommanderVersionApi(appSettings, api);
            CommanderVersionController controller          = FakeController(_cache, commanderVersionApi);

            int baseversionId = 1;

            Wp.CIS.LynkSystems.Model.CommanderVersion commanderVersion = new Wp.CIS.LynkSystems.Model.CommanderVersion()
            {
                BaseVersionID      = baseversionId,
                VersionDescription = "WPYPAK 6.02.07",
                CreatedByUser      = "******"
            };

            //.. Act

            var dinfo = await controller.CreateVersion(commanderVersion);

            var actualRecord      = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value;
            int newVersionId      = api.versionInfo.Max(s => Convert.ToInt32(s.VersionID));
            var newVersionMapping = api.epsMapping.Where(s => s.versionID == newVersionId).
                                    Select(s => new { s.pdlFlag, s.worldPayFieldName, s.worldPayTableName, s.worldPayJoinFields, s.worldPayCondition, s.worldPayOrderBy, s.worldPayFieldDescription, s.paramID, s.effectiveBeginDate, s.effectiveEndDate, s.viperCondition, s.viperFieldName, s.viperTableName, s.charStartIndex, s.charLength }).ToList();
            var oldVersionMapping = api.epsMapping.Where(s => s.versionID == baseversionId).
                                    Select(s => new { s.pdlFlag, s.worldPayFieldName, s.worldPayTableName, s.worldPayJoinFields, s.worldPayCondition, s.worldPayOrderBy, s.worldPayFieldDescription, s.paramID, s.effectiveBeginDate, s.effectiveEndDate, s.viperCondition, s.viperFieldName, s.viperTableName, s.charStartIndex, s.charLength }).ToList();

            var newTable = api.petroTable.Where(s => s.VersionID == newVersionId)
                           .Select(s => new { s.SchemaDef, s.DefaultXML, s.Active, s.CreatedDate, s.DefinitionOnly, s.EffectiveDate, s.LastUpdatedBy, s.LastUpdatedDate, s.TableID, s.TableName }).ToList();
            var oldTable = api.petroTable.Where(s => s.VersionID == baseversionId)
                           .Select(s => new { s.SchemaDef, s.DefaultXML, s.Active, s.CreatedDate, s.DefinitionOnly, s.EffectiveDate, s.LastUpdatedBy, s.LastUpdatedDate, s.TableID, s.TableName }).ToList();

            var currentVersion = api.versionInfo.Where(s => Convert.ToInt32(s.VersionID) == newVersionId).FirstOrDefault();

            //..Assert
            Assert.Equal(((bool)actualRecord), true);
            Assert.Equal(currentVersion, commanderVersion);
            Assert.Equal(newVersionMapping, oldVersionMapping);
            Assert.Equal(newTable, oldTable);
        }