예제 #1
0
        public void CreateDeckAndDeleteDeck()
        {
            //-- Arrange
            var newDeck = new DeckForCreationDto
            {
                Name = "test deck"
            };

            //-- Act
            var response = _decks.CreateDeck(newDeck, jsonMediaType).Result as CreatedAtRouteResult;

            var newDeckId   = (int)response.RouteValues["deckId"];
            var createdDeck = _flashCardRepository.GetDeck(newDeckId);

            //-- Assert
            Assert.IsNotNull(response);
            Assert.AreEqual("test deck", createdDeck.Name);


            /*--------- delete the deck ------------*/
            //-- Act
            _decks.DeleteDeck(newDeckId);

            var getResponse = _decks.GetDecks(jsonMediaType).Result as OkObjectResult;
            var getResult   = getResponse.Value as IEnumerable <DeckDto>;

            //-- Assert
            Assert.AreEqual(3, getResult.Count());
        }
예제 #2
0
        public async Task CreateDeck_InvalidObjectPassed_ReturnsBadRequest()
        {
            // Arrange
            var controller      = new DecksController(flashcardDbContextMock.Object, orderService, logger);
            var nameMissingDeck = new DeckDTO
            {
                Content         = "Uj Teszt csomag tartalma",
                Module          = Module.B,
                Deck_number     = 3,
                ApplicationUser = new ApplicationUserDTO
                {
                    Id                 = "268e543e-2020-ue63-a111-98321798c21",
                    Email              = "*****@*****.**",
                    Name               = "Teszt User 2",
                    Phone              = "063012345672",
                    Workplace          = "Teszt kornyezet2",
                    Create_module      = Module.E,
                    Will_create_module = Module.F,
                    Activated          = true
                }
            };

            controller.ModelState.AddModelError("Name", "Required");

            // Act
            var result = await controller.CreateDeck(nameMissingDeck);

            // Asssert
            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
예제 #3
0
        public async Task CreateDeck_RightObjectPassed_ReturnsCreatedAtAction()
        {
            // Arrange
            var controller = new DecksController(flashcardDbContextMock.Object, orderService, logger);
            var rightCard  = new DeckDTO
            {
                Name            = "Uj csomag neve",
                Content         = "Uj Teszt csomag tartalma",
                Module          = Module.B,
                Deck_number     = 3,
                ApplicationUser = new ApplicationUserDTO
                {
                    Id                 = "268e543e-2020-ue63-a111-98321798c21",
                    Email              = "*****@*****.**",
                    Name               = "Teszt User 2",
                    Phone              = "063012345672",
                    Workplace          = "Teszt kornyezet2",
                    Create_module      = Module.E,
                    Will_create_module = Module.F,
                    Activated          = true
                }
            };

            // Act
            var result = await controller.CreateDeck(rightCard);

            // Asssert
            Assert.IsType <CreatedAtActionResult>(result.Result);
        }
        public void CreateDeckTest(string deckName, Type expectedResultType, bool insertMethodCalled,
                                   bool insertMethodReturnValue, bool storageAlreadyContainsDeck)
        {
            deckStorageMock.Setup(storage =>
                                  storage.InsertOrUpdate(It.Is <Deck>(deck => deck.Name == deckName)))
            .Returns(insertMethodReturnValue);
            deckStorageMock.Setup(storage =>
                                  storage.Get(deckName))
            .Returns(storageAlreadyContainsDeck ? new Deck(deckName, new List <Card>()) : null);

            var result = controller.CreateDeck(new CreateArguments {
                Name = deckName
            });

            result.Should().BeOfType(expectedResultType);
            deckStorageMock.Verify(storage =>
                                   storage.InsertOrUpdate(It.Is <Deck>(deck => deck.Name == deckName)),
                                   insertMethodCalled ? Times.Once() : Times.Never());
        }