Exemplo n.º 1
0
        public async Task Sell_OpensNewOneAsync()
        {
            var storage = _fixture.CreateStorageWithNoOptions();
            var account = await _fixture.CreateAccountStorageWithUserAsync();

            var handler = new Sell.Handler(storage, account);

            await handler.Handle(
                OptionsTestsFixture.CreateSellCommand(),
                CancellationToken.None);

            Assert.Single(storage.SavedOptions);
            Assert.Equal(-1, storage.SavedOptions.Single().State.NumberOfContracts);
        }
Exemplo n.º 2
0
        public async Task Sell_OpensNewOneAsync()
        {
            var mock = new Mock <IPortfolioStorage>();

            mock.Setup(x => x.Save(It.IsAny <OwnedOption>(), It.IsAny <Guid>()))
            .Callback((OwnedOption option, Guid userId) =>
            {
                Assert.Equal(-1, option.State.NumberOfContracts);
            });

            var account = _fixture.CreateAccountStorageWithUserAsync();

            var handler = new Sell.Handler(mock.Object, account);

            await handler.Handle(
                OptionsTestsFixture.CreateSellCommand(),
                CancellationToken.None);
        }
Exemplo n.º 3
0
        public async Task SellingOption_Decreases()
        {
            var storage = _fixture.CreateStorageWithNoOptions();

            var handler = new Sell.Handler(
                storage,
                await _fixture.CreateAccountStorageWithUserAsync());

            await handler.Handle(
                OptionsTestsFixture.CreateSellCommand(),
                CancellationToken.None);

            await handler.Handle(
                OptionsTestsFixture.CreateSellCommand(),
                CancellationToken.None);

            var opt = storage.SavedOptions.Single();

            Assert.Equal(-2, opt.State.NumberOfContracts);
        }