示例#1
0
        public StockMarketForm()
        {
            //
            // Windows フォーム デザイナ サポートに必要です。
            //
            InitializeComponent();
            if (StockMarketConfig.debug)
            {
                this.ClientSize = new Size(850, 381);
            }
            forBuyEdit = new NumberChangeListener(onBuyEditChanged);
            numberBuy.onNumberChanged += forBuyEdit;
            forSellEdit = new NumberChangeListener(onSellEditChanged);
            numberSell.onNumberChanged += forSellEdit;
            numberSell.numberMax        = 0;
            StocksListHelper.buildStockMarketList(listview);
            listener = new AccountListener(onAccountChange);
            AccountManager.onAccountChange += listener;
            onAccountChange();

            chart.chart.ScaleTypeX = XAxisStyle.DAILY;
            chart.setScaleArray(new XAxisStyle[2] {
                XAxisStyle.DAILY, XAxisStyle.MONTHLY
            });
            chart.chart.ScaleTypeY = YAxisStyle.AUTOSCALE;
            chart.chart.area.setYRange(0, 15000);
            //chart.Invalidate();
        }
示例#2
0
        public void Login_ShouldReturnJWT_When_UserFound()
        {
            // Arrange
            var credentialEntities = new List <CredentialEntity>
            {
                new CredentialEntityBuilder().SetId(1).SetEmail("*****@*****.**").SetPassword("42818AAC3AEFB82B8A9E136A40657A0DD8582A0C6C544755806BC20E9D32D4E3").SetDummyRole("Gebruikert").Create(),
            };

            var mapperMock = new Mock <ICredentialDataMapper>(MockBehavior.Strict);

            mapperMock.Setup(x => x.Find(It.IsAny <Expression <Func <CredentialEntity, bool> > >())).Returns(credentialEntities);

            var listener = new AccountListener(mapperMock.Object, new LoggerFactory());

            var credentials = new Credential
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            // Act
            var result = listener.Login(new LoginCommand(credentials, ""));

            // Assert
            mapperMock.VerifyAll();
            Assert.IsTrue(result.Length > 0);
        }
示例#3
0
        public void Register_ShouldReturn_RegisterResultOk()
        {
            // Arrange
            var credentialEntities = new List <CredentialEntity>();

            var mapperMock = new Mock <ICredentialDataMapper>(MockBehavior.Strict);

            mapperMock.Setup(x => x.Find(It.IsAny <Expression <Func <CredentialEntity, bool> > >())).Returns(credentialEntities);
            mapperMock.Setup(x => x.Insert(It.IsAny <CredentialEntity>())).Returns(new CredentialEntity());

            var listener = new AccountListener(mapperMock.Object, new LoggerFactory());

            var credentials = new Credential
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            // Act
            var result = listener.Register(new RegisterCommand(credentials, ""));

            // Assert
            mapperMock.VerifyAll();
            Assert.AreEqual(RegisterResult.Ok, result);
        }
示例#4
0
 public void SubcribeToAccountUpdates(AccountListener accountListener)
 {
     _accountSubscription = new Subscription("MERGE", new[] { "ACCOUNT:" + _accountId }, new[] {
         "FUNDS", "PNL", "DEPOSIT", "USED_MARGIN",
         "AMOUNT_DUE", "AVAILABLE_CASH"
     });
     _accountSubscription.addListener(accountListener);
     _lsClient.subscribe(_accountSubscription);
 }
示例#5
0
        public void Validate_ShouldFail_When_NoJwtProvided()
        {
            // Arrange
            var listener = new AccountListener(null, new LoggerFactory());

            // Act
            var isValid = listener.Validate(new ValidateCommand(null, ""));

            // Assert
            Assert.IsFalse(isValid);
        }
示例#6
0
        public void Validate_ShouldSucceed()
        {
            // Arrange
            var listener = new AccountListener(null, new LoggerFactory());

            var jwt = new JSONWebToken(1, "*****@*****.**", new List <string>()
            {
                "Gebruikert"
            });

            // Act
            var isValid = listener.Validate(new ValidateCommand(jwt.Token, ""));

            // Assert
            Assert.IsTrue(isValid);
        }
示例#7
0
        public void AddRole_ShouldReturn_True()
        {
            // Arrange
            var credentials = new Credential
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            var credentialEntities = new List <CredentialEntity>()
            {
                new CredentialEntity()
                {
                    Email = credentials.Email, Password = credentials.Password, CredentialRoles = new List <CredentialRoleEntity>()
                }
            };
            CredentialEntity updateParam = null;

            var mapperMock = new Mock <ICredentialDataMapper>(MockBehavior.Strict);

            mapperMock.Setup(x => x.Find(It.IsAny <Expression <Func <CredentialEntity, bool> > >())).Returns(credentialEntities);
            mapperMock.Setup(x => x.Update(It.IsAny <CredentialEntity>()))
            .Callback <CredentialEntity>(entity =>
            {
                updateParam = entity;
            });

            var listener = new AccountListener(mapperMock.Object, new LoggerFactory());

            var roleRequest = new RoleRequest()
            {
                Email = credentials.Email, Role = Roles.Sales
            };

            // Act
            var result = listener.AddRole(new AddRoleCommand(roleRequest, ""));

            // Assert
            mapperMock.VerifyAll();
            Assert.IsTrue(result);
            Assert.IsNotNull(updateParam);
            Assert.AreEqual(roleRequest.Email, updateParam.Email);
            Assert.AreEqual(roleRequest.Role.ToString(), updateParam.CredentialRoles.FirstOrDefault().Role.Name);
        }
示例#8
0
        public void Login_ShouldThrow_DatabaseException_OnError()
        {
            // Arrange
            var mapperMock = new Mock <ICredentialDataMapper>(MockBehavior.Strict);

            mapperMock.Setup(x => x.Find(It.IsAny <Expression <Func <CredentialEntity, bool> > >())).Throws <Exception>();

            var listener = new AccountListener(mapperMock.Object, new LoggerFactory());

            // Act
            Action act = () =>
            {
                listener.Login(new LoginCommand(new Credential(), ""));
            };

            // Assert
            var exception = Assert.ThrowsException <DatabaseException>(act);

            Assert.AreEqual("Something unexpected happened while searching through the database", exception.Message);
            mapperMock.VerifyAll();
        }
示例#9
0
        public void AddRole_ShouldThrow_DatabaseException()
        {
            // Arrange
            var credentialEntities = new List <CredentialEntity>();

            var mapperMock = new Mock <ICredentialDataMapper>(MockBehavior.Strict);

            mapperMock.Setup(x => x.Find(It.IsAny <Expression <Func <CredentialEntity, bool> > >())).Returns(credentialEntities);

            var listener = new AccountListener(mapperMock.Object, new LoggerFactory());

            // Act
            Action act = () =>
            {
                listener.AddRole(new AddRoleCommand(new RoleRequest(), ""));
            };

            // Assert
            var exception = Assert.ThrowsException <DatabaseException>(act);

            Assert.AreEqual("Something unexpected happened while updating in the database", exception.Message);
            mapperMock.VerifyAll();
        }
示例#10
0
        public void Login_ShouldReturnEmptyJWT_When_NoUserFound()
        {
            // Arrange
            var credentialEntities = new List <CredentialEntity>();

            var mapperMock = new Mock <ICredentialDataMapper>(MockBehavior.Strict);

            mapperMock.Setup(x => x.Find(It.IsAny <Expression <Func <CredentialEntity, bool> > >())).Returns(credentialEntities);

            var listener = new AccountListener(mapperMock.Object, new LoggerFactory());

            var credentials = new Credential
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            // Act
            var result = listener.Login(new LoginCommand(credentials, ""));

            // Assert
            mapperMock.VerifyAll();
            Assert.IsTrue(result.Length == 0);
        }