Пример #1
0
        // ReSharper disable once InconsistentNaming
        public async Task Controller_Can_GET_All_Fake_Classifications() {
            // Arrange
            _ctrl = new AssetClassController(_mockRepo.Object) {
                Request = new HttpRequestMessage { RequestUri = new Uri("http://localhost/PIMS.Web.Api/api/AssetClass") },
                Configuration = new HttpConfiguration()
            };

            // Act
            var classifications = await _ctrl.GetAll();

            // Assert
            Assert.IsNotNull(classifications);
            Assert.GreaterOrEqual(classifications.Count(), 9);
            Assert.That(classifications, Is.Ordered.By("Description"));
        }
Пример #2
0
        // ReSharper disable once InconsistentNaming
        public async Task Controller_can_GET_a_single_Fake_classification_based_on_a_valid_asset_classification() {
            // Arrange
            _ctrl = new AssetClassController(_mockRepo.Object) {
                Request = new HttpRequestMessage { RequestUri = new Uri("http://localhost/PIMS.Web.Api/api/AssetClass/ETF") },
                Configuration = new HttpConfiguration()
            };

            // Act
            var result = await _ctrl.GetByClassification("ETF") as OkNegotiatedContentResult<IQueryable<AssetClass>>;


            // Assert
            Assert.IsNotNull(result);
            Assert.That(result.Content.First().LastUpdate, Is.EqualTo("ETF"));
            Assert.That(result.Content.Count(), Is.EqualTo(1));
        }
        // ReSharper disable once InconsistentNaming
        public async void Can_GET_an_Asset_Classification_By_Code()
        {

            // Arrange
            _ctrl = new AssetClassController(_repository) {
                Request = new HttpRequestMessage { RequestUri = new Uri(UrlBase + "/AssetClass/ETF") },
                Configuration = new HttpConfiguration()
            };

            // Act
            var assetClass = await _ctrl.GetByClassification("ETF") as OkNegotiatedContentResult<IQueryable<AssetClass>>;
            
            
            // Assert
            Assert.IsNotNull(assetClass);
            Assert.IsTrue(assetClass.Content.First().LastUpdate.Trim().ToUpper() == "ETF");
            Assert.That(assetClass.Content.ToList(), Is.Unique);

        }
        // ReSharper disable once InconsistentNaming
        public async Task Can_GET_All_Asset_Classifications()
        {
            // Arrange
            _ctrl = new AssetClassController(_repository) {
                Request = new HttpRequestMessage { RequestUri = new Uri(UrlBase + "/AssetClass") },
                Configuration = new HttpConfiguration()
            };
            

            // Act
            var classifications = await _ctrl.GetAll(); 


            // Assert
            Assert.IsNotNull(classifications);
            Assert.GreaterOrEqual(classifications.Count(), 15);
            Assert.That(classifications.First(x => x.LastUpdate.Trim() == "PFD").LastUpdate, Is.Unique);
            Assert.That(classifications.First(x => x.LastUpdate.Trim() == "PFD").Description, Is.EqualTo("Preferred Stock"));
        }
        // ReSharper disable once InconsistentNaming
        public async void Can_GET_an_Asset_Classification_By_Id()
        {
            // Arrange
            _ctrl = new AssetClassController(_repository) {
                Request = new HttpRequestMessage { RequestUri = new Uri(UrlBase + "/AssetClass/567f2176-2098-4800-bdf3-a2fc00a6be5a") },
                Configuration = new HttpConfiguration()
            };

            // Act
            var assetClass = await _ctrl.GetByClassificationId(new Guid("567f2176-2098-4800-bdf3-a2fc00a6be5a")) as OkNegotiatedContentResult<AssetClass>;

            // Assert
            Assert.IsNotNull(assetClass);
            Assert.IsTrue(assetClass.Content.KeyId == new Guid("567f2176-2098-4800-bdf3-a2fc00a6be5a"));
            Assert.IsTrue(assetClass.Content.LastUpdate.Trim().ToUpper() == "ETF");

        }
        // ReSharper disable once InconsistentNaming
        public async void Can_DELETE_an_Asset_Classification_By_Id() {

            // Arrange
            var existingGuid = new Guid();
            var preTestCtrl = new AssetClassController(_repository)
                                         {
                                            Request = new HttpRequestMessage { RequestUri = new Uri(UrlBase + "/AssetClass/TEST") },
                                            Configuration = new HttpConfiguration()
                                         };

            var existingAssetClass = await preTestCtrl.GetByClassification("TEST") as OkNegotiatedContentResult<IQueryable<AssetClass>>;
            if (existingAssetClass != null)
            {
                existingGuid = new Guid(existingAssetClass.Content.First().KeyId.ToString(CultureInfo.InvariantCulture.ToString()));
            }
            else
            {
                Assert.False(existingAssetClass == null);
            }


            _ctrl = new AssetClassController(_repository) {
                Request = new HttpRequestMessage { RequestUri = new Uri(UrlBase + "/AssetClass/" + existingGuid) },
                Configuration = new HttpConfiguration()
            };

            // Act
            var assetClass = await _ctrl.Delete(existingGuid) as OkNegotiatedContentResult<AssetClass>;


            // Assert
            Assert.IsNull(assetClass);
  
        }
        // ReSharper disable once InconsistentNaming
        public async void Can_PUT_Update_an_Asset_Classification_By_Asset_Class()
        {
           
            // Arrange
            _ctrl = new AssetClassController(_repository) {
                Request = new HttpRequestMessage { RequestUri = new Uri(UrlBase + "/AssetClass/TEST") },
                Configuration = new HttpConfiguration()
            };

                var editedClassification = new AssetClass
                                    {
                                        KeyId = new Guid("3437791f-3e3f-4f76-a266-a47600c39453"),
                                        LastUpdate = "TEST",
                                        Description = DateTime.Now.ToString("g")
                                    };


            // Act
            //var debugJsonForFiddler = TestHelpers.ObjectToJson(editedClassification);
            var assetClassResult = await _ctrl.UpdateAssetClass(editedClassification, editedClassification.LastUpdate.Trim()) as OkNegotiatedContentResult<AssetClass>;
                

            // Assert
            Assert.IsNotNull(assetClassResult);
           
        }
        // ReSharper disable once InconsistentNaming
        public async void Can_POST_a_New_Asset_Classification()
        {

            // Arrange
            _ctrl = new AssetClassController(_repository) {
                Request = new HttpRequestMessage { RequestUri = new Uri(UrlBase + "/AssetClass") },
                Configuration = new HttpConfiguration()
            };

            var newClassification = new AssetClass
                                        {
                                            LastUpdate = "TEST",
                                            Description = DateTime.Now.ToString("g")
                                        };

            // Act
            var debugJsonForFiddler = TestHelpers.ObjectToJson(newClassification);
            var response = await _ctrl.CreateNewAssetClass(newClassification) as CreatedNegotiatedContentResult<AssetClass>;
            
            
            // Assert
            Assert.IsNotNull(response);
            Assert.That(response.Location.AbsoluteUri.Contains("api/AssetClass/TEST"), Is.True);
 
        }