|
/****************************************************************************************************
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 ProductDetailPanelTest
{
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 create product method which in ProductDetailPanel")]
public void TestCreate()
{
ProductDetailPanel page = new ProductDetailPanel();
DetailPanelPageProxy proxy = new DetailPanelPageProxy(page);
IConcreteDataApi ConcreteDataApi = SpringContext.Current.GetObject<IConcreteDataApi>();
IMembershipApi membershipApi = SpringContext.Current.GetObject<IMembershipApi>();
using (var httpEnv = new HttpEnvironment())
{
httpEnv.SetRequestUrl(@"/ProductDetailPanel/DynamicPage.svc?MetadataDataTypeName=Product");
UserObject current = membershipApi.Get("admin");
httpEnv.SetSessionParaemeter("CurrentUser", current);
Guid guid = Guid.NewGuid();
string surfix = guid.ToString().Substring(0, 5);
TextBox TextBoxName = new TextBox();
TextBoxName.Text = "NewProduct" + surfix;
proxy.Set("TextBoxName", TextBoxName);
TextBox TextBoxNumber = new TextBox();
TextBoxNumber.Text = "100" ;
proxy.Set("TextBoxNumber", TextBoxNumber);
TextBox TextBoxManufactory = new TextBox();
TextBoxManufactory.Text = "Manufactory" + surfix;
proxy.Set("TextBoxManufactory", TextBoxManufactory);
TextBox TextBoxDescription = new TextBox();
TextBoxDescription.Text = "TextBoxDescription" + surfix;
proxy.Set("TextBoxDescription", TextBoxDescription);
DropDownList DropDownListCategory = new DropDownList();
ConcreteDataObject category = new ConcreteDataObject()
{
DeleteStatus = DeleteStatus.NotDeleted,
Name = "Category" + surfix,
Type = "ProductCategory",
Value = "Rapid" + surfix
};
ConcreteDataApi.Save(category);
ConcreteObjectIds.Add(category.Id);
DropDownListCategory.DataSource = new List<Guid>() { category.Id };
DropDownListCategory.DataBind();
proxy.Set("DropDownListCategory", DropDownListCategory);
ExtensionDataForm ProductExtensionDataForm = null;
proxy.Set("ProductExtensionDataForm", ProductExtensionDataForm);
string entity = proxy.Create();
ProductObjectIds.Add(new Guid(entity));
var dbcontext = DataContextFactory.Create<ProductManagementDataContext>();
Assert.IsTrue(dbcontext.Products.Where(x => 1 == 1).Select(x => x.Id).Contains(new Guid(entity)));
}
}
[Test, Description("Test the update product method which in ProductDetailPanel")]
public void TestUpdate()
{
ProductDetailPanel page = new ProductDetailPanel();
DetailPanelPageProxy proxy = new DetailPanelPageProxy(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");
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();
Guid product_id = dbcontext.Products.Where(x=>x.Name == "Name" + surfix).Select(x=>x.Id).FirstOrDefault();
ProductObjectIds.Add(product_id);
TextBox TextBoxName = new TextBox();
TextBoxName.Text = "NewProduct" + surfix;
proxy.Set("TextBoxName", TextBoxName);
TextBox TextBoxNumber = new TextBox();
TextBoxNumber.Text = "100";
proxy.Set("TextBoxNumber", TextBoxNumber);
TextBox TextBoxManufactory = new TextBox();
TextBoxManufactory.Text = "Manufactory" + surfix;
proxy.Set("TextBoxManufactory", TextBoxManufactory);
TextBox TextBoxDescription = new TextBox();
TextBoxDescription.Text = "TextBoxDescription" + surfix;
proxy.Set("TextBoxDescription", TextBoxDescription);
DropDownList DropDownListCategory = new DropDownList();
ConcreteDataApi.Save(category);
ConcreteObjectIds.Add(category.Id);
DropDownListCategory.DataSource = new List<Guid>() { category.Id };
DropDownListCategory.DataBind();
proxy.Set("DropDownListCategory", DropDownListCategory);
ExtensionDataForm ProductExtensionDataForm = null;
proxy.Set("ProductExtensionDataForm", ProductExtensionDataForm);
proxy.Update(product_id.ToString());
Assert.IsTrue(dbcontext.Products.Where(x => x.Id == product_id).Select(x => x.Manufactory).FirstOrDefault().Equals("Manufactory" + 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.