예제 #1
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 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);
  
        }