示例#1
0
        public void Should_TrimInput()
        {
            var answers = new[] { " spAces ", "       Extra    spaces    " };
            var word    = " WoRd     ";
            var command = new AddWordCommand(word, answers);

            command.Word.Should().Be("word");
            command.AcceptedAnswers.Should().BeEquivalentTo(new string[] { "spaces", "extra spaces" });
        }
示例#2
0
        public async Task <IActionResult> AddWord([FromBody] AddWordPostModel postData)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            var command = new AddWordCommand(postData.Word, postData.Answers);
            await _addWordCommandHandler.HandleAsync(command);

            var query       = FindItemsQuery.ByWord(postData.Word);
            var queryResult = await _findItemsQueryHandler.QueryAsync(query);

            var createdItem = queryResult.Single();

            string currentUri = Request?.Path ?? "/Words";

            return(new CreatedResult(currentUri.JoinPaths(createdItem.Id.ToString()), createdItem));
        }
示例#3
0
文件: Program.cs 项目: gobixm/learn
        private static void Main(string[] args)
        {
            var stringBuilder = new StringBuilder();

            var addShortWord = new AddWordCommand(stringBuilder, "short | ");
            var addLongWord = new AddWordCommand(stringBuilder, "veryLongCamelCaseWord | ");

            var commandProvider = new CommandProvider<AddWordCommand>();
            commandProvider.PerformCommand(addShortWord);
            commandProvider.PerformCommand(addLongWord);
            Console.WriteLine("Builder now is " + stringBuilder);
            commandProvider.PerformCommand(addShortWord);
            commandProvider.PerformCommand(addLongWord);
            commandProvider.PerformCommand(addLongWord);
            Console.WriteLine("Builder now is " + stringBuilder);
            commandProvider.UndoCommand();
            commandProvider.UndoCommand();
            Console.WriteLine("Builder now is " + stringBuilder);
            Console.ReadKey();
        }
示例#4
0
 public MainWindowVM()
 {
     using (FileStream fs = new FileStream("Words.dat", FileMode.OpenOrCreate))
     {
         BinaryFormatter formater = new BinaryFormatter();
         if (fs.Length > 0)
         {
             _wordsList = (ObservableCollection <Words>)formater.Deserialize(fs);
         }
         else
         {
             _wordsList = new ObservableCollection <Words>();
         }
     }
     deleteCommand   = new DeleteCommand(this);
     newWordCommand  = new AddWordCommand(this);
     sortCommand     = new SortCommand(this);
     ViewList        = new CollectionViewSource();
     ViewList.Source = _wordsList;
 }
        public async Task Should_AddNewWord(string word, string[] answers)
        {
            var options = new DbContextOptionsBuilder <LearningItemContext>()
                          .UseInMemoryDatabase("Add_Item")
                          .Options;

            using (var context = new LearningItemContext(options))
            {
                var command = new AddWordCommand(word, answers);
                var handler = new AddWordCommandHandler(context);
                await handler.HandleAsync(command);
            }

            using (var context = new LearningItemContext(options))
            {
                var items = await context.LearningItems.ToListAsync();

                var item = items.Single(x => x.ToBeGuessed == word && x.AcceptedAnswers.SequenceEqual(answers));
                item.Should().NotBeNull();
                item.ToBeGuessed.ShouldBeEquivalentTo(word);
                item.AcceptedAnswers.ShouldAllBeEquivalentTo(answers);
            }
        }