Exemplo n.º 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);
        }
        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;
        }
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
 private int FailWithoutForce()
 {
     SystemContext.ConsoleErrorWriteLine(
         $"Feature bit '{_opts.Name}' already exists. Use --force to overwrite existing feature bits.");
     return(1);
 }