public Task<Guid> Create(FundManager fundManager)
        {
            fundManager.Id = Guid.NewGuid();
            if (!_fundManagers.TryAdd(fundManager.Id, fundManager))
                throw new Exception("Cannot add manager - another manager with the same ID already exists."); // Unlikely as it's as the key is a GUID.

            return Task.FromResult(fundManager.Id);
        }
        public async Task ShouldGet()
        {
            var mock = new Mock<IFundManagerRepository>();
            var controller = new FundManagerController(mock.Object);
            var newGuid = Guid.NewGuid();
            var fundManager = new FundManager();
            mock.Setup(m => m.GetBy(newGuid)).Returns(Task.FromResult(fundManager));

            var result = controller.Get(newGuid);

            mock.Verify();
            Assert.That(await result, Is.EqualTo(fundManager));
        }
        public async Task ShouldAddItem()
        {
            var repo = new FundManagerMemoryDb();
            var beforeCount = (await repo.GetAll()).Count();
            var fundManager = new FundManager()
            {
                Name = "TestFundManager",
                Biography = "test bio",
                Location = Location.NewYork,
                ManagedSince = DateTime.Now.AddYears(-1)
            };

            repo.Create(fundManager);

            Assert.That(fundManager.Id, Is.Not.EqualTo(Guid.Empty));
            var afterCount = (await repo.GetAll()).Count();
            Assert.That(afterCount, Is.EqualTo(beforeCount + 1));
        }
        public async void ShouldGet()
        {
            var mockServiceClient = new Mock<IHttpClientWrapper>();
            var mockToFundManagerModelMapper = new Mock<IMapper<FundManager, FundManagerModel>>();
            var fundManager = new FundManager();
            var guid = Guid.NewGuid();
            mockServiceClient
                .Setup(m => m.GetAndReadFromContentGetAsync<FundManager>("api/FundManager/" + guid))
                .Returns(Task.FromResult(fundManager));
            var fundManagerModel = new FundManagerModel();
            mockToFundManagerModelMapper
                .Setup(m => m.Map(It.IsAny<FundManager>()))
                .Returns(fundManagerModel);
            var repository = new FundManagerModelRepository(
                mockServiceClient.Object,
                mockToFundManagerModelMapper.Object);

            var result = await repository.Get(guid);

            mockToFundManagerModelMapper.Verify();
            mockServiceClient.Verify();
            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.EqualTo(fundManagerModel));
        }
 public void Put(FundManager fundManager)
 {
     _repository.Update(fundManager.Id, fundManager);
 }
 public async Task<Guid> Post(FundManager fundManager)
 {
     return await _repository.Create(fundManager);
 }
 public void Update(Guid id, FundManager fundManager)
 {
     _fundManagers[id] = fundManager;
 }