public void Add_DependencyCalledOnce_Success()
        {
            // Arrange. Mock Character
            var character = new Character
            {
                Name = "Character_" + Guid.NewGuid(),
                Age  = 34,
                Id   = 2
            };

            Mock <ICharactersRepository> charactersRepository = new Mock <ICharactersRepository>();
            CharactersController         sut = new CharactersController(charactersRepository.Object);

            // Act. Add Character
            IActionResult result = sut.Add(character);

            // Assert. Verify Add action is called once
            charactersRepository.Verify(x => x.Add(character), Times.Once);
        }
        public void Add_Character_isRedirected()
        {
            // Arrange. Mock Character
            var character = new Character
            {
                Name = "Character_" + Guid.NewGuid(),
                Age  = 34,
                Id   = 2
            };

            Mock <ICharactersRepository> charactersRepository = new Mock <ICharactersRepository>();

            CharactersController sut = new CharactersController(charactersRepository.Object);

            // Act. Add Character
            IActionResult result = sut.Add(character);

            // Assert. Verify RedirectToActionResult is returned
            Assert.IsType <RedirectToActionResult>(result);
        }
        public void Add_Character_Duplicate_Fail()
        {
            // Arrange. Mock Character
            var character = new Character
            {
                Name = "Character_" + Guid.NewGuid(),
                Age  = 34,
                Id   = 2
            };

            Mock <ICharactersRepository> charactersRepository = new Mock <ICharactersRepository>();

            charactersRepository.Setup(x => x.GetCharacters()).Returns(new List <Character> {
                character
            });

            CharactersController sut = new CharactersController(charactersRepository.Object);

            // Act. Add duplicate Character
            IActionResult result = sut.Add(character);

            // Assert. Verify a character is not added.
            ViewResult viewResult = Assert.IsType <ViewResult>(result);
        }
예제 #4
0
        private static void SetNewDevice(PhonesController phones_ctrl)
        {
            Console.WriteLine("Введите название смартфона: ");
            string smartName;

            while (true)
            {
                smartName = Console.ReadLine();
                if (string.IsNullOrEmpty(smartName))
                {
                    Console.WriteLine("Название не может быть пустым.");
                }
                else
                {
                    break;
                }
            }

            phones_ctrl.AddnSetCurrent(smartName);


            Console.WriteLine($"Введите модель {smartName}:");
            var modelName = Console.ReadLine();

            var model      = new Model(phones_ctrl.current_phone, modelName);
            var model_ctrl = new ModelsController(phones_ctrl.current_phone);

            model_ctrl.Add(model);

            if (!model_ctrl.newModel)
            {
                Console.WriteLine("Вы ввели существующую модель. Е - изменить характеристики моделя. Q - отменить действие.");

                while (true)
                {
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.E)
                    {
                        break;
                    }
                    else if (key.Key == ConsoleKey.Q)
                    {
                        return;
                    }
                    else
                    {
                        Console.WriteLine("Неправильный ввод.");
                    }
                }
            }
            Console.WriteLine("Введите параметры экрана [пример: 6.53\", 2340x1080 (19.5:9)]: ");
            var screen = Console.ReadLine();

            Console.WriteLine("Введите параметры камеры [пример: 4 модуля, fullHD 60 к/с, видео 4K]: ");
            var camera = Console.ReadLine();

            Console.WriteLine("Введите параметры памяти [пример: 64 ГБ, слот для карты microSD]: ");
            var memory = Console.ReadLine();

            Console.WriteLine("Введите параметры hardware [пример: 8 ядер(а), 2 ГГц, оперативка 6 ГБ]: ");
            var hardware = Console.ReadLine();

            Console.WriteLine("Введите параметры аккумулятора [пример: 4500 мАч]: ");
            var battery = Console.ReadLine();


            var characteristiscks    = new Characteristic(screen, camera, memory, hardware, battery);
            var characteristick_ctrl = new CharactersController(model.Name);

            characteristick_ctrl.Add(characteristiscks);
            Console.WriteLine("Новый смартфон добавлен. Нажмите Enter кнопку чтобы продолжить.");
            Console.ReadLine();
        }