コード例 #1
0
        public async void GetProductsAsync_WithProductName_ShouldReturnProductsByName()
        {
            // Arrange
            var expectedResult = new List <Product>()
            {
                new Product {
                    Id = Guid.NewGuid(), Name = "product1"
                },
                new Product {
                    Id = Guid.NewGuid(), Name = "product111"
                }
            };

            ProductServiceMock.Setup(x => x.GetProductsByNameAsync("1")).ReturnsAsync(expectedResult);

            // Act
            var result = await ProductController.GetProductsAsync("1");

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(result);
            //convert the ok result from anonymous type to a dynamic so we can compare the results
            dynamic dResult = new DynamicObjectResultValue(okResult.Value);

            Assert.Equal(expectedResult, dResult.Items);
        }
コード例 #2
0
        public async Task TestBoardAddsMember()
        {
            BoardController controller = MakeController();

            IActionResult result = await controller.CreateAsync("TestAdd");

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            dynamic response = new DynamicObjectResultValue((result as OkObjectResult).Value);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.id is int);

            result = await controller.AddMember(response.id, new BoardController.MemberEmail
            {
                Email = User.Email,
            });

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));

            response = new DynamicObjectResultValue((result as OkObjectResult).Value);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success is bool);
            Assert.IsTrue(response.Success);
        }
コード例 #3
0
        public async void GetAllOptionsByProductIdAsync_ShouldReturnOk()
        {
            // Arrange
            var expectedProduct = new Product()
            {
                Id = Guid.NewGuid(), Name = "product"
            };

            var expectedOptions = new List <ProductOption>()
            {
                new ProductOption()
                {
                    Id = Guid.NewGuid(), Name = "Option1"
                }, new ProductOption()
                {
                    Name = "Option2"
                }
            };

            ProductServiceMock.Setup(x => x.GetAllOptionsByProductIdAsync(expectedProduct.Id)).ReturnsAsync(expectedOptions);

            // Act
            var result = await ProductController.GetAllOptionsByProductIdAsync(expectedProduct.Id);

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(result);

            dynamic dResult = new DynamicObjectResultValue(okResult.Value);

            Assert.Equal(expectedOptions, dResult.Items);
        }
コード例 #4
0
        public void ComputeNormalModesReturns500StatusCodeWhenKrakenComputingExceptionOccurs()
        {
            const string message       = "error";
            const int    statusCode500 = 500;

            var krakenServiceMock           = _krakenServiceMocks.ComputeModesThrowsKrakenComputingException(message);
            var krakenInputModelMapperMock  = _mappersMocks.KrakenInputModelMapper();
            var krakenResultModelMapperMock = _mappersMocks.KrakenResultModelMapper();
            var krakenInputModelValidator   = _modelValidatorMocks.ValidateReturnsEmptyList();

            var krakenController = new KrakenController(krakenServiceMock.Object, krakenInputModelMapperMock.Object,
                                                        krakenResultModelMapperMock.Object, krakenInputModelValidator.Object);

            var model = new KrakenInputModel();

            var objectResult = krakenController.ComputeNormalModes(model) as ObjectResult;

            Assert.NotNull(objectResult);

            Assert.Equal(statusCode500, objectResult.StatusCode);

            dynamic obj = new DynamicObjectResultValue(objectResult.Value);

            Assert.True(obj.expectedError);
            Assert.Equal(message, obj.error);
        }
コード例 #5
0
        public void ComputeNormalModesReturnsBadRequestWithValidationErrorsWhenModelIsNotValid()
        {
            var validationErrors = new List <string> {
                "error 1", "error 2"
            };

            var krakenServiceMock           = _krakenServiceMocks.ComputeModesReturnsKrakenComputingResult();
            var krakenInputModelMapperMock  = _mappersMocks.KrakenInputModelMapper();
            var krakenResultModelMapperMock = _mappersMocks.KrakenResultModelMapper();
            var krakenInputModelValidator   = _modelValidatorMocks.ValidateReturnsNotEmptyList(validationErrors);

            var krakenController = new KrakenController(krakenServiceMock.Object, krakenInputModelMapperMock.Object,
                                                        krakenResultModelMapperMock.Object, krakenInputModelValidator.Object);
            var model = new KrakenInputModel();

            var badRequest = krakenController.ComputeNormalModes(model) as BadRequestObjectResult;

            dynamic obj = new DynamicObjectResultValue(badRequest.Value);
            var     returnedValidationErrors = obj.validationErrors as List <string>;

            Assert.NotNull(badRequest);

            Assert.NotNull(returnedValidationErrors);

            Assert.Equal(returnedValidationErrors.Count, validationErrors.Count);
            Assert.Contains(validationErrors[0], returnedValidationErrors);
            Assert.Contains(validationErrors[1], returnedValidationErrors);
        }
コード例 #6
0
        public async Task GetById_ValidParams_ExpectSuccess()
        {
            var bidService = this._serviceProvider.GetRequiredService <IGenericRepository <BidModel> >();
            var bid        = new BidModel()
            {
                BettingId = 2, Amount = 1M, Side = false, BidId = 8, Coefficient = 2, Date = DateTime.Now, UserId = "TestUser", WalletId = 1, Paid = false, PaymentStatus = PaymentStatus.Confirmed, Status = false, PaymentAddress = "mhheFUrieWV2zVsdWXNZkqSmeSVjkbXWer"
            };
            var bidList = new List <BidModel>()
            {
                bid
            };

            bidService.Create(bidList[0]);

            var result = await this.bidController.GetById(2);

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            CollectionAssert.AreEqual(obj.list, bidList);
        }
コード例 #7
0
        public async Task GetArchive_NoParams_ExpectSuccess()
        {
            var result = await this.bettingController.GetArchive();

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsTrue(obj.result);
        }
コード例 #8
0
        public async Task GetById_InvalidParams_ExpectError()
        {
            var result = await this.bettingController.GetById(4);

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsFalse(obj.result);
        }
コード例 #9
0
        public async Task GetById_ValidParams_ExpectSuccess()
        {
            var result = await this.bettingController.GetById(1);

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
            Assert.AreEqual(obj.list, ((List <BettingModel>) this.bettingModels)[0]);
        }
コード例 #10
0
        public async Task RemoveWalletAddress_GivenValidInvalidId_ExpectSuccess()
        {
            var result = await this.walletController.Remove(100);

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsFalse(obj.result);
        }
コード例 #11
0
        public async Task GetById_ValidParams_ExpectSuccessEmptyList()
        {
            var result = await this.bidController.GetById(4);

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsTrue(obj.result);
            CollectionAssert.AreEqual(obj.list, new List <BidModel>());
        }
コード例 #12
0
        public async Task Create_InvalidBetId_ExpectError()
        {
            var result = await this.bidController.Create(new BidModel()
            {
                WalletId = 1, BettingId = 3, Side = true
            });

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsFalse(obj.result);
        }
コード例 #13
0
        public async Task CreateWalletAddress_GivenValidModel_ExpectSuccess()
        {
            var result = await this.walletController.Create(new WalletModel()
            {
                Address = "WalletAddress"
            });

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsTrue(obj.result);
        }
コード例 #14
0
        public async Task ForgotPassword_GivenValidUserModel_ExpectSuccess()
        {
            var result = await this.accountController.ForgotPassword(new ForgotPasswordModel()
            {
                Email = "*****@*****.**"
            });

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsTrue(obj.result);
        }
コード例 #15
0
        public async Task Login_GivenNotExistUser_ExpectError()
        {
            var result = await this.accountController.Login(
                new LoginModel()
            {
                Email = "*****@*****.**", Password = "******"
            });

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsNotNull(obj.code);
        }
コード例 #16
0
        public async Task Register_GivenValidUserModelButExistedEmail_ExpectError()
        {
            var result = await this.accountController.Register(
                new RegisterModel()
            {
                Email = "*****@*****.**", Password = "******"
            });

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsNotNull(obj.code);
        }
コード例 #17
0
        public async Task Register_GivenValidUserModel_ExpectSuccess()
        {
            var result = await this.accountController.Register(
                new RegisterModel()
            {
                Email     = "*****@*****.**",
                Password  = "******",
                FirstName = "asd",
                LastName  = "asd"
            });

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsNotNull(obj.token);
        }
コード例 #18
0
        public async Task TestBoardGetsCreated()
        {
            BoardController controller = MakeController();

            IActionResult result = await controller.CreateAsync("Test");

            OkObjectResult okResult = result as OkObjectResult;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(okResult.Value, typeof(object));

            dynamic response = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(response);

            Assert.IsTrue(response.id is int);

            Board board = context.Boards.Find(response.id);

            Assert.AreEqual(board.BoardName, "Test");
        }
コード例 #19
0
        public async Task GetWalletAddresses_NoParams_ExpectSuccess()
        {
            // add wallets
            var repository  = this._serviceProvider.GetRequiredService <IGenericRepository <WalletModel> >();
            var listWallets = new List <WalletModel>()
            {
                new WalletModel()
                {
                    UserId = "TestUser", Address = "TestAddress1"
                },
                new WalletModel()
                {
                    UserId = "TestUser", Address = "TestAddress2"
                },
                new WalletModel()
                {
                    UserId = "TestUser", Address = "TestAddress3"
                }
            };

            repository.Create(listWallets[0]);
            repository.Create(listWallets[1]);
            repository.Create(listWallets[2]);
            repository.Create(new WalletModel()
            {
                UserId = "SomeOtherUser", Address = "TestAddress3"
            });

            var result = await this.walletController.Get();

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
            CollectionAssert.AreEqual(obj.list, listWallets);
        }
コード例 #20
0
        public async Task Create_ValidParams_ExpectSuccess()
        {
            var result = await this.bidController.Create(new BidModel()
            {
                WalletId = 1, BettingId = 1, Side = true
            });

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsTrue(obj.result);

            Assert.AreEqual(obj.bid.UserId, "TestUser");
            Assert.AreEqual(obj.bid.WalletId, 1);
            Assert.AreEqual(obj.bid.Amount, 0M);
            Assert.AreEqual(obj.bid.PaymentAddress, "mhheFUrieWV2zVsdWXNZkqSmeSVjkbXWer");
            Assert.IsTrue(obj.bid.Side);
            Assert.AreEqual(obj.bid.PaymentStatus, PaymentStatus.None);
            Assert.IsFalse(obj.bid.Paid);
        }
コード例 #21
0
        public async Task ChangePassword_GivenValidUserModel_ExpectSuccess()
        {
            var httpContext = this.serviceProvider.GetRequiredService <IHttpContextAccessor>().HttpContext;

            httpContext.User = new ClaimsPrincipal(
                new ClaimsIdentity(new GenericIdentity("*****@*****.**"), new[] { new Claim("ID", "TestUser") }));
            httpContext.RequestServices = this.serviceProvider;

            this.accountController.ControllerContext.HttpContext = httpContext;

            var result = await this.accountController.ChangePassword(new RestorePasswordModel()
            {
                OldPassword = "******", NewPassword = "******"
            });

            var okResult = result as OkObjectResult;

            dynamic obj = new DynamicObjectResultValue(okResult.Value);

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsTrue(obj.result);
        }