|
/****************************************************************************************************
Copyright (C) 2010 RapidWebDev Organization (http://rapidwebdev.org)
Author: Tim, Legal Name: Long Yi, Email: tim.long.yi@RapidWebDev.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RapidWebDev.UI.DynamicPages;
using RapidWebDev.Platform.Web.DynamicPage;
using RapidWebDev.Mocks.UIMocks;
using RapidWebDev.Mocks;
using RapidWebDev.UI.Services;
using RapidWebDev.Platform.Linq;
using RapidWebDev.Platform;
using RapidWebDev.Common;
using RapidWebDev.Common.Data;
using RapidWebDev.UI.DynamicPages.Configurations;
using NUnit.Framework;
using System.Web.UI;
using RapidWebDev.Platform.Initialization;
using RapidWebDev.Platform.Web.Controls;
using System.Web.UI.WebControls;
using RapidWebDev.ExtensionModel.Web.Controls;
using ProductManagement.Web;
using ProductManagement.DataModel;
namespace RapidWebDev.Tests.ProductManagement
{
[TestFixture]
public class ProductDynamicPageTest
{
List<Guid> ConcreteObjectIds = new List<Guid>();
List<Guid> ProductObjectIds = new List<Guid>();
[TearDown]
public void CleanUp()
{
IConcreteDataApi ConcreteDataApi = SpringContext.Current.GetObject<IConcreteDataApi>();
foreach (var id in ConcreteObjectIds)
{
ConcreteDataObject obj = ConcreteDataApi.GetById(id);
obj.DeleteStatus = DeleteStatus.Deleted;
ConcreteDataApi.Save(obj);
}
using (var dbContext = DataContextFactory.Create<ProductManagementDataContext>())
{
var deleted = dbContext.Products.Where(x => ProductObjectIds.Contains(x.Id));
dbContext.Products.DeleteAllOnSubmit(deleted);
dbContext.SubmitChanges();
}
}
[Test, Description("Test the Query product method which in ProductDynamicPage")]
public void TestQuery()
{
ProductDynamicPage page = new ProductDynamicPage();
DynamicPageProxy proxy = new DynamicPageProxy(page);
IConcreteDataApi ConcreteDataApi = SpringContext.Current.GetObject<IConcreteDataApi>();
IAuthenticationContext authenticationContext = SpringContext.Current.GetObject<IAuthenticationContext>();
IMembershipApi membershipApi = SpringContext.Current.GetObject<IMembershipApi>();
Guid guid = Guid.NewGuid();
string surfix = guid.ToString().Substring(0, 5);
using (var httpEnv = new HttpEnvironment())
{
httpEnv.SetRequestUrl(@"/ProductDynamicPage/DynamicPage.svc?MetadataDataTypeName=Product");
#region create product
var dbcontext = DataContextFactory.Create<ProductManagementDataContext>();
ConcreteDataObject category = new ConcreteDataObject()
{
DeleteStatus = DeleteStatus.NotDeleted,
Name = "Category" + surfix,
Type = "ProductCategory",
Value = "Rapid" + surfix
};
ConcreteDataApi.Save(category);
ConcreteObjectIds.Add(category.Id);
Product obj = new Product()
{
Name = "Name" + surfix,
Number = "100",
CategoryId = category.Id,
ApplicationId = authenticationContext.ApplicationId,
Description = "description" + surfix,
Manufactory = "Manufactory",
CreatedBy = authenticationContext.User.UserId,
CreatedOn = DateTime.Now,
ExtensionDataTypeId = Guid.Empty
};
dbcontext.Products.InsertAllOnSubmit(new List<Product>() { obj });
dbcontext.SubmitChanges();
#endregion
Guid product_id = dbcontext.Products.Where(x => x.Name == "Name" + surfix).Select(x => x.Id).FirstOrDefault();
ProductObjectIds.Add(product_id);
QueryParameterExpression expression = new QueryParameterExpression("Name", QueryFieldOperators.Equal, "Name" + surfix);
SortExpression sort = new SortExpression("Name");
QueryParameter parameters = new QueryParameter()
{
//Expressions = express,
PageIndex = 0,
PageSize = 10,
SortExpression = sort
};
parameters.Expressions.Add(expression);
QueryResults results = proxy.Query(parameters);
foreach (var result in results.Results)
{
Assert.IsTrue(DataBinder.Eval(result, "Name").ToString().Equals("Name" + surfix));
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I've worked as a software architect and developer based on Microsoft .NET framework and web technology since 2002, having rich experience on SaaS, multiple-tier web system and website development. I've devoted into open source project development since 2003, and have created 3 main projects including DataQuicker (ORM), ExcelQuicker (Excel Report Generator), and RapidWebDev (Enterprise-level CMS)
I worked in BenQ (8 mo), Bleum (4 mo), Newegg (1 mo), Microsoft (3 yr) and Autodesk (5 yr) before 2012. Now I own a startup company in Shanghai China to deliver the exceptional results to global internet users by leveraging the power of Internet and the local excellence.