コード例 #1
0
        private async Task <int> HandleFeatureBitAlreadyExists(DataException e)
        {
            int returnValue;

            if (e.Message == ($"Cannot add. Feature bit with name '{_opts.Name}' already exists."))
            {
                returnValue = !_opts.Force ? FailWithoutForce() : await ForceUpdate();
            }
            else
            {
                returnValue = 1;
                SystemContext.ConsoleErrorWriteLine(e.ToString());
            }

            return(returnValue);
        }
コード例 #2
0
        public void ItShouldBeAbleToUseASubstituteForConsoleDotErrorDotWriteLine()
        {
            // Arrange
            var builder = new StringBuilder();

            SystemContext.ConsoleErrorWriteLine = s => builder.Append(s);

            // Act
            SystemContext.ConsoleErrorWriteLine("foo" + Environment.NewLine);

            // Assert
            Assert.Equal("foo" + Environment.NewLine, builder.ToString());

            // Afterwards
            SystemContext.ConsoleErrorWriteLine = null;
        }
コード例 #3
0
        public async Task <int> RunAsync()
        {
            int returnValue = 0;
            var name        = _opts.Name;
            var def         = await _repo.GetByNameAsync(name);

            if (def == null)
            {
                SystemContext.ConsoleErrorWriteLine($"Feature bit '{_opts.Name}' could not be found.");
                returnValue = 1;
            }
            else
            {
                await _repo.RemoveAsync(def);

                SystemContext.ConsoleWriteLine("Feature bit removed.");
            }

            return(returnValue);
        }
コード例 #4
0
        public async Task <int> RunAsync()
        {
            int returnValue = 0;

            try
            {
                IFeatureBitDefinition newBit = BuildBit();
                await _repo.AddAsync(newBit);

                SystemContext.ConsoleWriteLine("Feature bit added.");
            }
            catch (DataException e)
            {
                returnValue = await HandleFeatureBitAlreadyExists(e);
            }
            catch (Exception e)
            {
                returnValue = 1;
                SystemContext.ConsoleErrorWriteLine(e.ToString());
            }

            return(returnValue);
        }
コード例 #5
0
 private int FailWithoutForce()
 {
     SystemContext.ConsoleErrorWriteLine(
         $"Feature bit '{_opts.Name}' already exists. Use --force to overwrite existing feature bits.");
     return(1);
 }