public AllocationController() { departmentManager = new DepartmentManager(); courseManager = new CourseManager(); componentManager = new ComponentManager(); allocationManager = new AllocationManager(); }
public void GetAllFundEmpty() { var alloc = new AllocationManager(LoggerFactory, _fetcher, null); alloc.SetInitialConfiguration(new Portfolio(new Dictionary <Currency, Balance>())); var funds = alloc.GetAllFunds(); Assert.NotNull(funds); Assert.Empty(funds.AllBalances()); }
public void SetAllocationNoLockedFunds() { var alloc = new AllocationManager(LoggerFactory, _fetcher, null); var currency = new Currency("ETH"); Assert.Throws <AllocationUnavailableException>(() => alloc.SetInitialConfiguration(new Portfolio(new Dictionary <Currency, Balance>() { { currency, new Balance(currency, 1, 2) }, }))); }
public void SetAllocationNoFreeFunds() { var alloc = new AllocationManager(LoggerFactory, _fetcher, null); var currency = new Currency("ETH"); var allMoney = _fetcher.GetPortfolio().Data.GetAllocation(currency).Free; Assert.Throws <AllocationUnavailableException>(() => alloc.SetInitialConfiguration(new Portfolio(new Dictionary <Currency, Balance>() { { currency, new Balance(currency, allMoney + 1, 0) }, }))); }
public void SetAllocationHappyFlow() { var alloc = new AllocationManager(LoggerFactory, _fetcher, null); var currency = new Currency("ETH"); alloc.SetInitialConfiguration(new Portfolio(new Dictionary <Currency, Balance>() { { currency, new Balance(currency, 2, 0) }, })); Assert.Equal(2, alloc.GetAvailableFunds(currency).Free); Assert.Equal(0, alloc.GetAvailableFunds(currency).Locked); }
private AllocationManager MakeDefaultAllocation() { var alloc = new AllocationManager(LoggerFactory, _fetcher, null); alloc.SetInitialConfiguration(_fetcher.GetPortfolio().Data); // Free up at least 10 SNGLS (ObscureCoin) alloc.UpdateAllocation( new TradeExecution( Balance.Empty(new Currency(ObscureCoin)), new Balance(new Currency(ObscureCoin), 10, 0))); return(alloc); }
public void AllocationManagerTest_HandleMessage_ExceptionWhenGetMetaCountByKey() { // Arrange _allocationLoggerMock.Setup(x => x.Log(LogLevel.Critical, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >())); _aggregationManagerMock.Setup(x => x.AddToAllocationRepo(It.IsAny <string>(), It.IsAny <string>())); _aggregationManagerMock.Setup(x => x.GetMetaCountByKey(It.IsAny <string>())).Throws(new Exception()); _aggregationManagerMock.Setup(x => x.EnrichAndSendMessage(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <string>())); AllocationManager objectUnderTest = new AllocationManager(_allocationLoggerMock.Object, _configMock.Object, _aggregationManagerMock.Object); // Action var result = objectUnderTest.HandleMessage("247d7eb3-2fbe-4b3c-84ef-f3580f5c6331", "Blah blah"); // Assert _allocationLoggerMock.Verify(x => x.Log(LogLevel.Critical, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once()); _aggregationManagerMock.Verify(x => x.AddToAllocationRepo(It.IsAny <string>(), It.IsAny <string>()), Times.Once()); _aggregationManagerMock.Verify(x => x.GetMetaCountByKey(It.IsAny <string>()), Times.Once()); _aggregationManagerMock.Verify(x => x.EnrichAndSendMessage(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <string>()), Times.Never()); }
public void AllocationManagerTest_HandleMessage_Success() { // Arrange _allocationLoggerMock.Setup(x => x.Log(LogLevel.Critical, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >())); _aggregationManagerMock.Setup(x => x.AddToAllocationRepo(It.IsAny <string>(), It.IsAny <string>())); _aggregationManagerMock.Setup(x => x.GetMetaCountByKey(It.IsAny <string>())); _aggregationManagerMock.Setup(x => x.EnrichAndSendMessage(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <string>())); String badMessage = ""; AllocationManager objectUnderTest = new AllocationManager(_allocationLoggerMock.Object, _configMock.Object, _aggregationManagerMock.Object); // Action var result = objectUnderTest.HandleMessage(Guid.NewGuid().ToString(), "Blah blah"); // Assert _allocationLoggerMock.Verify(x => x.Log(LogLevel.Critical, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Never()); _aggregationManagerMock.Verify(x => x.AddToAllocationRepo(It.IsAny <string>(), It.IsAny <string>()), Times.Once()); _aggregationManagerMock.Verify(x => x.GetMetaCountByKey(It.IsAny <string>()), Times.Once()); _aggregationManagerMock.Verify(x => x.EnrichAndSendMessage(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <string>()), Times.Once()); }
public void ValidateAllocationsSetRequired() { var allocationManager = new AllocationManager(LoggerFactory, _fetcher, null); Currency c = new Currency("ETH"); Assert.Throws <ArgumentNullException>(() => allocationManager.GetAvailableFunds(c)); Assert.Throws <ArgumentNullException>(() => allocationManager.GetAllFunds()); Assert.Throws <ArgumentNullException>(() => allocationManager.QueueTrade( new TradeProposal(TradingPair.Parse("EOSETH"), new Balance(c, 10, 10)), () => new OrderUpdate( orderId: 0, tradeId: 0, orderStatus: OrderUpdate.OrderStatus.New, orderType: OrderUpdate.OrderTypes.Limit, createdTimestamp: 0, setPrice: 0, side: OrderSide.Buy, pair: TradingPair.Parse("EOSETH"), setQuantity: 0))); }
public User Create(User user, string password, string origin) { AllocationManager allocationManager = new AllocationManager(); ParkingManager parkingManager = new ParkingManager(); // No Password Provided if (string.IsNullOrWhiteSpace(password)) { throw new CmpException("Password is required"); } // Checking If Email ALready Exists if (_context.Users.Any(x => x.Email == user.Email)) { throw new CmpException("Email " + user.Email + " is already taken"); } // Checking If the User is First User var isFirstUser = _context.Users.Count() == 0; // if First User, then Admin Role is granted if (isFirstUser) { user.Role = "Admin"; } // various conditionals to revoke another Admin Role // and, pass relevant User role to users if (string.IsNullOrWhiteSpace(user.Role)) { user.Role = "User"; } if (user.Role != "User" && user.Role != "AllocationManager" && user.Role != "ParkingManager" && user.Role != "Admin") { user.Role = "User"; } var role = user.Role == "Admin"; if (user.Role == "Admin" && !isFirstUser) { user.Role = "User"; } // declaring PasswordHash and PasswordSalt Blobs byte[] passwordHash, passwordSalt; // Creating PasswordHash and PasswordSalt for Password CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; // Saving Data for AllocationManager if (user.Role == "AllocationManager") { allocationManager.Name = user.Name; allocationManager.Email = user.Email; allocationManager.Address = user.Address; allocationManager.City = user.City; allocationManager.State = user.State; allocationManager.Phone = user.Phone; allocationManager.PasswordHash = user.PasswordHash; allocationManager.PasswordSalt = user.PasswordSalt; allocationManager.Created = DateTime.Now; _context.AllocationManagers.Add(allocationManager); _context.SaveChanges(); } // Saving Data for ParkingManager if (user.Role == "ParkingManager") { parkingManager.Name = user.Name; parkingManager.Email = user.Email; parkingManager.Address = user.Address; parkingManager.City = user.City; parkingManager.State = user.State; parkingManager.Phone = user.Phone; parkingManager.PasswordHash = user.PasswordHash; parkingManager.PasswordSalt = user.PasswordSalt; parkingManager.Created = DateTime.Now; _context.ParkingManagers.Add(parkingManager); _context.SaveChanges(); } user.Created = DateTime.Now; user.VerificationToken = randomTokenString(); _context.Users.Add(user); _context.SaveChanges(); // Comment Out to send Verification Email // sendVerificationEmail(user, origin); return(user); }
public void ConstructorHappyFlow() { var unused = new AllocationManager(LoggerFactory, _fetcher, null); }