public async void ShouldCreate()
        {
            var mockServiceClient            = new Mock <IHttpClientWrapper>();
            var mockToFundManagerModelMapper = new Mock <IMapper <FundManager, FundManagerModel> >();
            var guid             = Guid.NewGuid();
            var fundManager      = new FundManager();
            var fundManagerModel = new FundManagerModel()
            {
                Biography    = "Some",
                Location     = Location.London,
                ManagedSince = DateTime.Now,
                Name         = "Fred",
                Id           = guid
            };

            mockServiceClient
            .Setup(m => m.GetAndReadFromContentGetAsync <FundManager>("api/FundManager/" + guid))
            .Returns(Task.FromResult(fundManager));

            mockToFundManagerModelMapper
            .Setup(m => m.Map(It.IsAny <FundManager>()))
            .Returns(fundManagerModel);
            var repository = new FundManagerModelRepository(
                mockServiceClient.Object,
                mockToFundManagerModelMapper.Object);

            var result = await repository.Create(fundManagerModel);

            mockToFundManagerModelMapper.Verify();
            mockServiceClient.Verify();
            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.EqualTo(fundManagerModel));
        }
        /// <summary>
        /// Taskes a neewly created fund manager and sends it to be added
        /// </summary>
        public async Task <FundManagerModel> Create(FundManagerModel model)
        {
            var fundManager = _toModelMapper.ReverseMap(model);
            await _client.PutFromContentPutAsync("api/FundManager/", fundManager);

            return(model);
        }
        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));
        }
        /// <summary>
        /// Takes either an updated fund manager and updates its record
        /// </summary>
        public async Task <FundManagerModel> Update(FundManagerModel fundManagerModel)
        {
            var fundManager = _toModelMapper.ReverseMap(fundManagerModel);
            await _client.PostFromContentPostAsync <FundManager>("api/FundManager/", fundManager);

            return(fundManagerModel);
        }
示例#5
0
        public async void ShouldGetIndexPage()
        {
            var mock = new Mock <IFundManagerModelRepository>();
            var fundManagerModels = new FundManagerModel[0].AsEnumerable();

            mock.Setup(m => m.GetAll()).Returns(Task.FromResult(fundManagerModels));
            var controller = new FundManagerController(mock.Object);

            var result = await controller.Index(1, string.Empty, null);

            Assert.That(result, Is.TypeOf <ViewResult>());
            mock.Verify();
            Assert.That(((ViewResult)result).Model, Is.EqualTo(fundManagerModels));
        }
示例#6
0
        public async void ShouldGetDetailsPage()
        {
            var guid             = Guid.NewGuid();
            var mock             = new Mock <IFundManagerModelRepository>();
            var fundManagerModel = new FundManagerModel();

            mock.Setup(m => m.Get(guid)).Returns(Task.FromResult(fundManagerModel));
            var controller = new FundManagerController(mock.Object);

            var result = await controller.Details(guid);

            Assert.That(result, Is.TypeOf <ViewResult>());
            mock.Verify();
            Assert.That(((ViewResult)result).Model, Is.EqualTo(fundManagerModel));
        }
示例#7
0
        public async void ShouldCreateFundManage()
        {
            var mock = new Mock <IFundManagerModelRepository>();
            var fm   = new FundManagerModel()
            {
                Biography    = "Some",
                Location     = Location.London,
                ManagedSince = DateTime.Now,
                Name         = "Fred"
            };

            mock.Setup(m => m.Create(fm)).Returns(Task.FromResult(fm));
            var controller = new FundManagerController(mock.Object);
            var result     = await controller.Create(fm);

            Assert.That(result, Is.TypeOf <RedirectToRouteResult>());
            mock.Verify();
        }
        public async Task <ActionResult> Create([Bind(Include = "Name,ManagedSince,Biography,Location")] FundManagerModel fundsManager)
        {
            ViewBag.ResultsSaved = false;
            if (ModelState.IsValid)
            {
                try
                {
                    await _repository.Create(fundsManager);

                    ViewBag.ResultsSaved = true;
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("FundManagerError", "Create: " + ex.Message);
                }
            }
            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,ManagedSince,Biography,Location")] FundManagerModel fundsManager)
        {
            ViewBag.ResultsSaved = false;
            if (ModelState.IsValid)
            {
                try
                {
                    await _repository.Update(fundsManager);

                    ViewBag.ResultsSaved = true;
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("FundManagerError", "Edit: " + ex.Message);
                }
            }

            return(View(fundsManager));
        }
示例#10
0
        public async void ShouldEditFundManage()
        {
            var guid = Guid.NewGuid();
            var mock = new Mock <IFundManagerModelRepository>();
            var fm   = new FundManagerModel()
            {
                Id           = guid,
                Biography    = "Some1",
                Location     = Location.London,
                ManagedSince = DateTime.Now,
                Name         = "Fred1"
            };

            mock.Setup(m => m.Update(fm)).Returns(Task.FromResult(fm));
            var controller = new FundManagerController(mock.Object);
            var result     = await controller.Edit(fm);

            Assert.That(result, Is.TypeOf <ViewResult>());
            mock.Verify();
            Assert.That(((ViewResult)result).Model, Is.EqualTo(fm));
        }